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. 网络状态诊断工具——netstat命令

    netstat命令可以用来查询整个系统的网络状态.百度百科的定义如下: Netstat的定义是: Netstat是在内核中访问网络连接状态及其相关信息的程序,它能提供TCP连接,TCP和UDP监听,进 ...

  2. redis集群数据迁移txt版

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

  3. 多vps管理面板

           iis7远程桌面连接工具,又叫做iis7远程桌面管理软件,是一款绿色小巧,功能实用的远程桌面管理工具,其界面简洁,操作便捷,能够同时远程操作多台服务器,并且多台服务器间可以自由切换,适用 ...

  4. CommandPattern(命令模式)-----Java/.Net

    命令模式(Command Pattern)是一种数据驱动的设计模式,它属于行为型模式.请求以命令的形式包裹在对象中,并传给调用对象.调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象,该 ...

  5. Callable,阻塞队列,线程池问题

    一.说说Java创建多线程的方法 1. 通过继承Thread类实现run方法   2. 通过实现Runnable接口 3. 通过实现Callable接口 4. 通过线程池获取 二. 可以写一个Call ...

  6. 1090 危险品装箱 (25分)C语言

    集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否 ...

  7. ElementUi 两个表格反选

    ElementUi 两个表格反选 1.先看看实现的图 表格内容显示 <el-row :gutter="20"> <el-col :span="16&qu ...

  8. spring boot使用拦截器

    1.编写一个拦截器 首先,我们先编写一个拦截器,和spring mvc方式一样.实现HandlerInterceptor类,代码如下 package com.example.demo.intercep ...

  9. Big Event

    666DHG的大事记 2019.4.15 \(\text{ }\text{ }\text{ }\)注册洛谷 2019.8.10 \(\text{ }\text{ }\text{ }\)Luogu\(\ ...

  10. Java设计模式之三种工厂模式

    工厂模式实现了创建者和调用者的分离,实现了更好的解耦.   详细分类: 1) 简单工厂模式(静态工厂模式): 2) 工厂方法模式: 3) 抽象工厂模式 面向对象设计的基本原则: 1)       OC ...