OpenCV几个绘图函数
矩形
rectangle(Mat& img,Point pt1, Point pt2, const Scalar&color, int thickness=1,int lineType=8, int shift=0)
rectangle(Mat& img,Rect rec, const Scalar&color, int thickness=1, int lineType=8,int shift=0)
intthickness为-1 则填充矩形 lineType线形
线
line(Mat& img, Point pt1,Point pt2, const Scalar& color, int thickness=1, int lineType=8,int shift=0)
圆
circle(Mat&img, Point center, int radius, const Scalar&color,int thickness=1, intl ineType=8, int shift=0)
center圆心 radius半径
椭圆
ellipse(Mat& img, Point center,Size axes, double angle, double startAngle, double endAngle, const Scalar& color,int thickness=1, int lineType=8, int shift=0)
axes:横竖大小, angle旋转角度
折线
polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )
文字
void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
test文字 org左下坐标
例子:
---------
/*
绘图
*/
#include <cv.h>
#include <highgui.h>
#include <math.h> using namespace cv;
using namespace std; int main(int argc, char **argv)
{
Mat canvas(,,CV_8UC3,Scalar(,,)); line(canvas, Point(,),Point(,),Scalar(), , );
line(canvas, Point(,),Point(,),Scalar(), , );
line(canvas, Point(,),Point(,),Scalar(,,), , );
line(canvas, Point(,),Point(,),Scalar(), , ); rectangle(canvas, Rect(Point(,),Point(,)),Scalar(,,),-,);
rectangle(canvas, Rect(Point(,),Point(,)),Scalar(,,),,);
rectangle(canvas, Rect(Point(,),Point(,)),Scalar(,,),,); circle(canvas, Point(,),, Scalar(,,),);
circle(canvas, Point(,),, Scalar(,,),);
circle(canvas, Point(,),, Scalar(,,),);
ellipse(canvas, Point(,),Size(,),,,,Scalar(,,),); putText(canvas,"(50,50)",Point(,),,,Scalar());
putText(canvas,"(300,100)",Point(,),,,Scalar());
putText(canvas,"(250,350)",Point(,),,,Scalar());
putText(canvas,"(50,300)",Point(,),,,Scalar()); Point ps[][];
ps[][] = Point(,);
ps[][] = Point(,);
ps[][] = Point(,);
ps[][] = Point(,);
const Point* pts[]={ps[]};
int pn[]={};
polylines(canvas,pts,pn,,true,Scalar()); namedWindow("canvas", CV_WINDOW_AUTOSIZE);
imshow("canvas", canvas);
waitKey(); return ;
}
---------
end