OpenCV 提供很多绘制线曲线的函数,还有在图像上写字的函数。常用的函数:
(1)画线
CV_EXPORTS_W void line(InputOutputArray img,
Point pt1,
Point pt2,
const Scalar& color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0);
(2)画矩形
CVvoid rectangle(InputOutputArray img,
Point pt1,
Point pt2,
const Scalar& color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0);
(3)画圆
void circle(InputOutputArray img, Point center, int radius,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
(4)画椭圆
void ellipse(InputOutputArray img, Point center,
Size axes,double angle, double startAngle, double endAngle,const Scalar& color, int thickness = 1,int lineType = LINE_8, int shift = 0);
(5)画多边形
void fillPoly(Mat& img, const Point** pts,const int* npts, int ncontours,const Scalar& color, int lineType = LINE_8, int shift = 0, Point offset = Point() );
(6)在图上写字
void putText( InputOutputArray img, const String& text, Point org,int fontFace, double fontScale, Scalar color,int thickness = 1, int lineType = LINE_8,bool bottomLeftOrigin = false );
运行效果图:
本文源代码在Debug–64下编译运行,ZIP包中包含开发环境,可直接编译运行。