OpenCV3入门(三)基本绘图函数
2024-10-08 07:21:28
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
尊重原创技术文章,转载请注明。
最新文章
- windows下关闭进程
- jquery.css 最简单的用法
- 在ASP.NET MVC应用程序中实现Server.Transfer()类似的功能
- 区间dp笔记√
- POJ1416——Shredding Company(DFS)
- Linux安装Jdk,CentOS安装Jdk
- Linux项目一
- Android中绘制圆角矩形图片及任意形状图片
- iScroll屏幕滑动函数封装总结
- SDN第四次上机作业
- user-agent | what is the ";user-agent"; ?
- [CTSC2018]暴力写挂
- Oracle提取中文字符串拼音首字母函数
- jQuery-iframe加载完成后触发的事件监听
- qt中QtreeWidget与QstackWidget关联的问题
- 20155224 聂小益 《基于Arm实验箱的接口测试和应用》 课程设计报告
- 学习笔记_J2EE_SSM_01_spring+springMVC+Mybatis整合_XML配置示例
- eclipse3.4配置的tomcat server如何部署以前的web项目?
- 使用PowerShell为SSAS Role添加Membership
- node.js 与java 的主要的区别是什么