OpenCV常用繪圖函數:
rectangle()函數------用於繪製矩形
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);
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);
}
小結:這些畫圖函數常用作識別結果的標記。