绘制直线
cv::line(InputArrayOutputArray img,Point p1, Point p2, const Scalar& color,int thickness=1,int lineType=LINE_8,int shift=0);
绘制圆形
cv::circle(InputOutputArray img,Point center,int radius, const Scalar& color,int thickness=1,int lineType=LINE_8,int shift=0);
绘制椭圆形
cv::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);
输入,中心坐标,半轴长,旋转角度,
绘制矩形
cv::rectangle(InputArrayOutputArray img,Point p1, Point p2, const Scalar& color,int thickness=1,int lineType=LINE_8,int shift=0);
绘制多边形
cv::fillPoly(InputArrayOutputArray img,const Point** pts, const int* npts,int ncontours, const Scalar& color,int thickness=1,int lineType=LINE_8,int shift=0,Point offset=point());
绘制文字
cv::putText(InputArrayOutputArray img,const String* text, Point org,int fontFace, double fontScalar,Scalar color,int thickness=1,int lineType=LINE_8,bool bottomLeftOrigin=false);
  • 目前OpenCV只支持英文
案例
#include<opencv2/opencv.hpp>
int draw_(){
Mat img=Mat::zeros(Size(512,512),CV_8UC3);
//圆形
circle(img,Point(37,37),17,Scalar(255,255,255),-1);//实心圆
circle(img,Point(57,57),13,Scalar(255,255,255),3);//空心圆

//直线
line(img,Point(100,100),Point(200,200),Scalar(255,255,255),2,LINE_4,0)
//椭圆
ellipse(img,Point(300,300),Size(100,50),0,0,135,Scalar(255,255,255),-1);//实心
//矩形
rectangle(img,Point(400,400),Point(470,450),Scalar(255,255,255),-1)
//多边形
Point p12[2][6];
p12[0][0]=Point(72,200);
p12[0][1]=Point(142,204);
p12[0][2]=Point(226,263);
p12[0][3]=Point(172,310);
p12[0][4]=Point(117,319);
p12[0][5]=Point(15,260);
p12[1][0]=Point(72,200);
p12[1][1]=Point(142,204);
p12[1][2]=Point(226,263);
p12[1][3]=Point(172,310);
p12[1][4]=Point(117,319);
p12[1][5]=Point(15,260);
Point p5[5];
p5[0]=Point(350,83);
p5[1]=Point(463,90);
p5[2]=Point(500,171);
p5[3]=Point(421,194);
p5[4]=Point(338,141);

const Point* pts[3]={p12[0],p12[1],p12};
int npts[]={6,6,5};

fillPoly(img,pts,npts,3,Scalar(255,255,255),8);
//文字
putText(img,"learn opencv4",Point(500,500),2,1,Scalar(255,255,255));
imshow("draw",img);
waitKey(0);
return 1;
}