1、代码如下:
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>using namespace cv;int main()
{Size size(800,800);Size size2(300, 200);Mat img = Mat::zeros(size, CV_8UC3);Point p1(100, 200);Point p2(200, 400);Point p3(300, 300);Point p4(500, 500);line(img,p1,p2,Scalar(255,255,255));//绘制直线,p1为起点,p2为终点,线的颜色为白色ellipse(img, RotatedRect(p3,size2,45), Scalar(0, 0, 255));//绘制椭圆,旋转中心为p3,大小为size2,旋转角度45,颜色红rectangle(img, Rect(50,50,100,100), Scalar(0, 255, 0)); // 绘制矩形,起点坐标(50,50),大小(100,100),颜色绿色circle(img, p4, 100, Scalar(255, 0, 0));//绘制圆,中心坐标p4,半径100,颜色蓝imshow("绘图", img);waitKey(0);}
2、运行结果如下: