有所更改,参数不求完备,但求实用。源码参考D:\source\opencv-3.4.9\samples\cpp\drawing.cpp
#include<opencv2\opencv.hpp> #include<iostream> using namespace cv; using namespace std; int main() { string wndname = "Drawing Demo";//窗体名 Mat image = Mat::zeros(700, 1000, CV_8UC3); //700行1000列的三维黑色图 //直线 //line(image, Point(10, 10), Point(200, 200), Scalar(0,0,255), 3); //图,起始坐标,终点坐标,颜色,粗细 //箭头 //arrowedLine(image, Point(10, 10), Point(200, 200), Scalar(0, 0, 255), 3); //图,起始坐标,终点坐标,颜色,粗细 //矩形 //rectangle(image, Point(10, 10), Point(200, 200), Scalar(0, 0, 255), 3);//图,左上角坐标,右下角坐标,颜色,粗细 //十字标记 //drawMarker(image, Point(200, 200), Scalar(0, 0, 255), MARKER_CROSS, 20,3);//图,坐标,颜色,十字型,大小,粗细 //圆 //circle(image, Point(200, 200), 50, Scalar(0, 0, 255), 3);//图,圆心,半径,颜色,粗细 //椭圆 //ellipse(image, Point(200, 200), Size(50, 100), 0, 0 - 100, 0 + 200, Scalar(0, 0, 255), 3);//图,坐标,宽高,角度,起始角度,终止角度,颜色,粗细 ////连线、填充的封闭图形 //Point pt[2][3]; //2行3列的点矩阵,一行一个图形(一行中的前n个点依次连接,n在npt[]中指定) //pt[0][0].x = 10; //pt[0][0].y = 10; //pt[0][1].x = 50; //pt[0][1].y = 50; //pt[0][2].x = 100; //pt[0][2].y = 10; //pt[1][0].x = 150; //pt[1][0].y = 50; //pt[1][1].x = 200; //pt[1][1].y = 10; //pt[1][2].x = 250; //pt[1][2].y = 50; //const Point* ppt[2] = { pt[0], pt[1] }; //int npt[] = { 3, 3 };//每一行从前到后连接的点的个数n ////polylines(image, ppt, npt, 2, true, Scalar(0, 0, 255), 3);//图,点矩阵,每行连接的点数,图个数(画出几行),是否闭合,颜色,粗细 //fillPoly(image, ppt, npt, 2, Scalar(0, 0, 255)); //填充的封闭图形 //文字 putText(image, "OpenCV forever!", Point(50, 50), FONT_HERSHEY_TRIPLEX, 1.5, Scalar(0, 0, 255), 2);//图,文本,左下角坐标,字类型,字大小,颜色,粗细 imshow(wndname, image); waitKey(); return 0; }