示例代码
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char const *argv[])
{
Mat img = Mat::zeros(600, 600, CV_8UC3);
// 绘制椭圆 中心点位置Point, 宽200, 高100, 旋转60度, 绘制从0度到360, 颜色红
ellipse(img, Point(img.rows/2, img.cols/2), Size(200, 100), 45, 0, 360, Scalar(0, 0, 255));
// 绘制圆 中心点位置Point, 半径100, 颜色红, 厚度 -1 表示充填
circle(img, Point(img.rows/2, img.cols/2), 100, Scalar(0, 0, 255), -1);
// 绘制线段
line(img, Point(0, 0), Point(img.rows, img.cols), Scalar(0, 0, 255));
// 绘制多边形 创建保存多边形顶点的数组
Point triPoints[3] = {Point(200, 40), Point(150, 80), Point(250, 80)};
const Point *ppt[] = { triPoints };
int npt[] = { 3 };
// ppt 保存多边形数组指针的数组, npt 保存每个多边形的顶点个数的数组, 1 只一个多边形
fillPoly(img, ppt, npt, 1, Scalar(0, 255, 0));
imshow("结果", img);
waitKey(0);
return 0;
}
运行结果

网友评论