OpenCV常用绘图函数:
line()函数------用于绘制直线
circle()函数------用于绘制圆
rectangle()函数------用于绘制矩形
rectangle()函数------用于绘制矩形
ellipse()函数------用于绘制椭圆
fillPoly()/polylines()函数------用 于绘制多边形
putText()函数------用于添加文字
1)、绘制直线-----line()
CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2,const Scalar& color,int thickness=1,int line Type=8,int shift=0);
2)、绘制圆-----circle()
CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius,const Scalar& color,int thickness=1,int line Type=8,int shift=0);
3)、绘制矩形-----rectangle()
CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2,const Scalar& color,int thickness=1,int lne Type=8,int shift=0);
CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Rect rec,const Scalar& color,int thickness=1,int line Type=8,int shift=0);
CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center,Size axes,double angle,double startAngle,double endAngle,const Scalar& color,int thickness=1,int line Type=8,int shift=0);
CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, const RotatedRect& box,const Scalar& color,int thickness=1,int line Type=8,int shift=0);
CV_EXPORTS_W void fillPoly(CV_IN_OUT Mat& img, Point** pts,const int* npts,int ncontours,const Scalar& color,int line Type=8,int shift=0,Poinr offset=Point());//填充多边形
CV_EXPORTS_W void polylines(CV_IN_OUT Mat& img, Point** pts,const int* npts,int ncontours,bool isClosed,const Scalar& color,int thickness=1,int line Type=8,int shift=0);//非填充多边形
CV_EXPORTS_W void putText(CV_IN_OUT Mat& img,const string& text,int fontFace,double fontScale,Scalar color,int thickness=1,int line Type=8,bool bottomLeftOrigin=false);
ex:
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
void main()
{
Mat img(300, 300, CV_8UC3, Scalar(0, 0, 0));
line(img, Point(10, 10), Point(200, 200), Scalar(0, 255, 255), 10, 8); //画线
circle(img, Point(150, 150), 100, Scalar(255, 255, 0), -1, 8); //画圆
rectangle(img, Point(10, 10), Point(240, 200), Scalar(0, 0, 255), 2, 8); //画矩形
rectangle(img, Rect(10, 10, 230, 190), Scalar(0, 0, 255), -1, 8); //填充矩形
ellipse(img, Point(150, 150), Size(100, 50), 45, 0, 360, Scalar(0, 255, 255), -1, 8); //画椭圆
ellipse(img, RotatedRect(Point(150, 150), Size(100, 50), 0), Scalar(0,255,0), 2, 8);
Point ppt[] = {Point(120, 50), Point(180, 50), Point(210, 100), Point(180, 150), Point(120, 150), Point(90, 100)};
const Point* pts[] = {ppt};
int npt[] ={6};
fillPoly(img, pts, npt, 1, Scalar(0, 255, 255), 8); //画填充多边形
polylines(img, pts, npt, 1, true, Scalar(0, 154, 209), 2, 8); //画非填充多边形
putText(img, "China", Point(100, 100), CV_FONT_HERSHEY_COMPLEX, 2, Scalar(0, 255, 255), 2, 8);
waitKey(0);
}
小结:这些画图函数常用作识别结果的标记。