多边形的填充与绘制
1.定义画布图像与点
Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3);
Point p1(100, 100);
Point p2(350, 100);
Point p3(450, 280);
Point p4(320, 480);
Point p5(80, 400);
- 绘制封闭多边形
vector<Point>pts;
pts.push_back(p1);
pts.push_back(p2);
pts.push_back(p3);
pts.push_back(p4);
pts.push_back(p5);
polylines(canvas, pts, true, Scalar(0, 0, 255), 2, 8, 0);
fillPoly(canvas, pts, Scalar(255, 255, 0), 8, 0);
3.快速绘制多幅
contours.push_back(pts);
drawContours(canvas, contours, -1, Scalar(255, 0, 0), -1);