polylines()
fillpoly
drawContours
polylines
polylines(canvas, pts, true, Scalar(0, 255, 0), 1, 8, 0);
参数 | 说明 |
---|---|
img | 作为画布的矩阵 |
pts | 折线顶点数组 |
npts | 折线顶点个数 |
ncontours | 待绘制折线数 |
isClosed | 是否是闭合折线(多边形) |
color | 折线的颜色 |
thickness | 折线粗细 |
lineType | 线段类型 |
shift | 缩放比例(0是不缩放,4是1/4) |
fullpoly(canvas, pts, Scalar(255, 255, 0));
drawContours
drawContours(canvas, contours, 0, Scalar(0, 0, 255), -1, 8);
Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3); //创建画布:512*512,纯白色
int w = canvas.cols;
int h = canvas.rows;
//多边形顶点位置
Point p1(100, 100);
Point p2(300, 150);
Point p3(300, 350);
Point p4(250, 450);
Point p5(50, 450);
//创建point容器
std::vector<Point> pts;
//录入顶点
pts.push_back(p1);
pts.push_back(p2);
pts.push_back(p3);
pts.push_back(p3);
pts.push_back(p4);
pts.push_back(p5);
//polylines(canvas, pts, true, Scalar(0, 255, 0), 1, 8, 0);
//fillPoly(canvas, pts, Scalar(0, 255, 0));
std::vector<std::vector<Point>> contours;
contours.push_back(pts);
drawContours(canvas, contours, 0, Scalar(0, 0, 255), -1, 8);
imshow("绘制多边形", canvas);