1、函数原型

OpenCV包含大量的绘图函数,如直线、圆、椭圆、多边形等。下面是部分函数的原型。

/** @brief Draws a line segment connecting two points.*/
CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
int thickness = , int lineType = LINE_8, int shift = ); int thickness=, int line_type=, int shift=, double tipLength=0.1); /** @brief Draws a simple, thick, or filled up-right rectangle.*/
CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
const Scalar& color, int thickness = ,
int lineType = LINE_8, int shift = ); /** @brief Draws a simple or filled circle with a given center and radius.*/
CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius,
const Scalar& color, int thickness = ,
int lineType = LINE_8, int shift = ); /** @brief Draws a simple or thick elliptic arc or fills an ellipse sector.*/
CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,
double angle, double startAngle, double endAngle,
const Scalar& color, int thickness = ,
int lineType = LINE_8, int shift = ); /** @brief Fills the area bounded by one or more polygons. */
CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
const Scalar& color, int lineType = LINE_8, int shift = ,
Point offset = Point() ); /** @brief Draws a text string.*/
CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org,
int fontFace, double fontScale, Scalar color,
int thickness = , int lineType = LINE_8,
bool bottomLeftOrigin = false );

2、示例

#include <opencv2/opencv.hpp>
#include <iostream>
#include <ctype.h> using namespace std;
using namespace cv;
void DrawLine(Mat img, Point start, Point end)
{
int thickness = ;
int lineType = ;
line(img, start, end, Scalar(, , ), thickness, lineType);
} void DrawEllipse(Mat img, double angle)
{
int thickness = ;
int lineType = ;
ellipse(img,
Point(img.rows / 2.0, img.cols / 2.0),
Size(img.rows / 4.0, img.cols / 16.0),
angle,
,
,
Scalar(, , ),
thickness,
lineType);
} void DrawFilledCircle(Mat img, Point center)
{
int thickness = -;
int lineType = ;
circle(img,
center,
img.rows / 32.0,
Scalar(, , ),
thickness,
lineType);
} void DrawRect(Mat img, Point start, Point end)
{
rectangle(img, start, end, Scalar(, , ), );
} int main() {
CvFont font;
Mat m = Mat::zeros(, , CV_8UC3);
m.setTo(cv::Scalar(, 10, )); DrawEllipse(m, );
DrawEllipse(m, );
DrawEllipse(m, );
DrawEllipse(m, -); DrawFilledCircle(m, Point(m.rows / , m.cols / ));
DrawRect(m,Point(m.rows/,m.cols/),Point(m.rows/+m.rows/, m.cols/+ m.cols/));
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, , , );
IplImage* image = &IplImage(m); // Mat -> IplImage 类型转换
cvPutText(image, "Hello World !", cvPoint(, ), &font, cvScalar(, , , ));
imshow("椭圆图", m);
waitKey();
}

输出如下。

3、遇到的问题

1)Error:OpenCV 不存在从 "cv::Mat" 到 "CvArr的转换

中间需要IplImage 衔接一下.

cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, , , );

IplImage* image = &IplImage(m); // Mat -> IplImage 类型转换

cvPutText(image, "Hello World !", cvPoint(, ), &font, cvScalar(, , , ));

imshow("椭圆图", m);

4、参考文献

1、《OpenCV3 编程入门》,电子工业出版社,毛星雨著

2、《学习OpenCV》,清华大学出版社,Gary Bradski, Adrian kaehler著

3、OpenCV 中的绘图函数

https://www.cnblogs.com/yujiachen/p/7672417.html?utm_source=debugrun&utm_medium=referral

尊重原创技术文章,转载请注明。

https://www.cnblogs.com/pingwen/p/12296477.html

OpenCV3入门(三)基本绘图函数的更多相关文章

  1. TypeScript入门三:TypeScript函数类型

    TypeScript函数类型 TypeScript函数的参数 TypeScript函数的this与箭头函数 TypeScript函数重载 一.TypeScript函数类型 在上一篇博客中已经对声明Ty ...

  2. 数据分析与展示——Matplotlib基础绘图函数示例

    Matplotlib库入门 Matplotlib基础绘图函数示例 pyplot基础图表函数概述 函数 说明 plt.plot(x,y,fmt, ...) 绘制一个坐标图 plt.boxplot(dat ...

  3. Swift语法基础入门三(函数, 闭包)

    Swift语法基础入门三(函数, 闭包) 函数: 函数是用来完成特定任务的独立的代码块.你给一个函数起一个合适的名字,用来标识函数做什么,并且当函数需要执行的时候,这个名字会被用于“调用”函数 格式: ...

  4. 《MATLAB从入门到放弃》二维曲线和图形绘制基础(二):使用Help文档学习line、plot、plotyy、subplot、hold绘图函数

    目录: »  plot 最常用的二维曲线绘图函数 >  帮助文档 >  基本使用语法 >  线条的样式.符号和颜色调整 >  图形属性调整 >  使用图形句柄进行设置 » ...

  5. Javascript入门(三)函数

    Javascript函数 一.函数定义与执行 <script type="text/javascript"> //define function fun1(){ ale ...

  6. VS2010/MFC编程入门之四十九(图形图像:CDC类及其屏幕绘图函数)

    上一节中鸡啄米讲了文本输出的知识,本节的主要内容是CDC类及其屏幕绘图函数. CDC类简介 CDC类是一个设备上下文类. CDC类提供了用来处理显示器或打印机等设备上下文的成员函数,还有处理与窗口客户 ...

  7. opencv-python教程学习系列4-opencv绘图函数

    前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍opencv绘图函数,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: 系统 ...

  8. 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数

    [<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同,     传统编程语言,甚至cad ...

  9. OpenCV中的绘图函数-OpenCV步步精深

    OpenCV 中的绘图函数 画线 首先要为画的线创造出环境,就要生成一个空的黑底图像 img=np.zeros((512,512,3), np.uint8) 这是黑色的底,我们的画布,我把窗口名叫做i ...

随机推荐

  1. ELK部署检测nginx日志demo

    ELK E: ElasticSearch 搜索引擎 存储 https://www.elastic.co/cn/downloads/elasticsearch L: Logstash 日志收集 http ...

  2. CSRF绕过后端Referer校验

    CSRF绕过后端Referer校验分正常情况和不正常的情况,我们这里主要讨论开发在写校验referer程序时,不正常的情况下怎么进行绕过. 正常情况 正常的情况指服务器端校验Referer的代码没毛病 ...

  3. aliPayPlus 科普使用

    本文出自APICloud官方论坛, 感谢论坛版主City7的分享. 首先到 https://open.alipay.com/platform/manageHome.htm 申请应用上线 支付宝网关:这 ...

  4. Java 使用Scanner时的NoSuchElementException异常

    做实验时设计了一个类,在类中的两个不同函数中分别创建了两个Scanner对象,并且在各个函数的结尾使用了close()方法,结果在运行时产生了NoSuchElementException异常. 实验的 ...

  5. hdfs断电报错解决

    一,/home/hadoop/tmp/dfs/name/current 目录下查看文件二,1.stop hadoop所有的服务;2.重新格式化namenode即可: hadoop根目录下: hadoo ...

  6. 2019CSP初赛游记

    Day 0 作为一个初三的小蒟蒻…… 对于J+S两场比赛超级紧张的…… 教练发的神奇的模拟卷…… 我基本不会…… 就这样吧…… Day 1 Morning 不知道怎么就进了考场…… 周围坐的全是同学( ...

  7. [洛谷P3621] [APIO2007] 风铃

    Description 你准备给弟弟 Ike 买一件礼物,但是,Ike 挑选礼物的方式很特别:他只喜欢那些能被他排成有序形状的东西. 你准备给 Ike 买一个风铃.风铃是一种多层的装饰品,一般挂在天花 ...

  8. set去重

    public static void main(String[] args){ List<String> list = new ArrayList<String>(); lis ...

  9. 用canvas绘制标准的五星红旗

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Java多态之Father f=new Son();

    成员变量静态方法看左边,非静态方法编译看左边,运行看右边. 左边Father f其实是定义了一个Father类的对象,而右边new Son()可以只理解为是一个重写了Father类方法的对象. 因此, ...