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

最新文章

  1. windows下关闭进程
  2. jquery.css 最简单的用法
  3. 在ASP.NET MVC应用程序中实现Server.Transfer()类似的功能
  4. 区间dp笔记√
  5. POJ1416——Shredding Company(DFS)
  6. Linux安装Jdk,CentOS安装Jdk
  7. Linux项目一
  8. Android中绘制圆角矩形图片及任意形状图片
  9. iScroll屏幕滑动函数封装总结
  10. SDN第四次上机作业
  11. user-agent | what is the &quot;user-agent&quot; ?
  12. [CTSC2018]暴力写挂
  13. Oracle提取中文字符串拼音首字母函数
  14. jQuery-iframe加载完成后触发的事件监听
  15. qt中QtreeWidget与QstackWidget关联的问题
  16. 20155224 聂小益 《基于Arm实验箱的接口测试和应用》 课程设计报告
  17. 学习笔记_J2EE_SSM_01_spring+springMVC+Mybatis整合_XML配置示例
  18. eclipse3.4配置的tomcat server如何部署以前的web项目?
  19. 使用PowerShell为SSAS Role添加Membership
  20. node.js 与java 的主要的区别是什么

热门文章

  1. Elasticsearch基本概念和使用
  2. vc++简单的vector动态数组实现
  3. 小小知识点(三十)集中式大规模和无小区大规模MIMO
  4. Win10删除桌面上的回收站、计算机、网络等图标
  5. python文件及目录操作
  6. SnowflakeId雪花ID算法,分布式自增ID应用
  7. python的list()函数
  8. 图解kubernetes scheduler基于map/reduce无锁设计的优选计算
  9. DOCKER学习_017:Docker-Compose介绍
  10. NABCD项目分析