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. redis集群数据迁移txt版

    ./redis-trib.rb create --replicas 1 192.168.112.33:8001 192.168.112.33:8002 192.168.112.33:8003 192. ...

  2. my_mysql

    ###一键偷懒YUM安装MySQbL### 1.安装mysql数据库 #yum install -y mariadb-server  mariadb 2.登录mysql数据库常用选项 -h:指定服务端 ...

  3. shell点名脚本不重复人名

    效果如图: 代码如下: #!/bin/bash #Author:GaoHongYu #QQ: #Time:-- :: #Name:dm.sh #Version:V1. stu=(刘一 陈二 张三 李四 ...

  4. .sarut后缀病毒,勒索病毒

    前两天朋友的电脑中所有的文件后缀名都被改为.sarut 一看就是中了勒索病毒 每个文件夹下都有一个勒索信 查资料后发现这个病毒是STOP病毒的变种 可能是朋友使用windows激活工具了,然后这个病毒 ...

  5. goland编辑器永久激活

    1 下载goland破解文件补丁 链接: https://pan.baidu.com/s/1i3dFAwscXPzKV-1imvgkdA 提取码: furt 2 打开goland的安装文件,将下载好的 ...

  6. Spring Boot 2.X(十九):集成 mybatis-plus 高效开发

    前言 之前介绍了 SpringBoot 整合 Mybatis 实现数据库的增删改查操作,分别给出了 xml 和注解两种实现 mapper 接口的方式:虽然注解方式干掉了 xml 文件,但是使用起来并不 ...

  7. UIBPlayer (视频播放)demo分享

    本文出自APICloud官方论坛 UIBPlayer 封装了百度云播放器 SDK.本模块带有UI方案,打开后为一个具有完整功能的播放器界面.百度云播放器突破 Android.iOS 平台对视频格式的限 ...

  8. 使用RobotFramework的DataBaseLibrary(Java实现)

    RobotFramework能用Python和Jython两条腿走路.但有的时候你得选一条.今天就碰上个问题,为了整合其它模块必须用Java实现的DataBaseLibrary 其实实它很简单,记录步 ...

  9. KVM管理工具 WebVirtMgr

    WEB管理工具 WebVirtMgr WebVirtMgr是一个基于libvirt的Web界面,用于管理虚拟机.它允许您创建和配置新域,并调整域的资源分配.VNC查看器为来宾域提供完整的图形控制台.K ...

  10. C#中TripleDES对应Java中的DESede即大家说的3DES,附C#及Java加解密结果一致的控制台程序例子

    直接上代码了. Java控制台代码: package Test; import java.security.Key; import javax.crypto.Cipher; import javax. ...