Mat bg = Mat::zeros(Size(512, 512), CV_8UC3);
Point p1(100, 100);
Point p2(350, 100);
Point p3(450, 280);
Point p4(320, 450);
Point p5(80, 400);
std::vector<Point> pts;
pts.push_back(p1);
pts.push_back(p2);
pts.push_back(p3);
pts.push_back(p4);
pts.push_back(p5);
polylines(bg, pts, true, Scalar(0, 0, 255), 2, 8, 0);
fillPoly(bg, pts, Scalar(0, 255, 255),8, 0);
std::vector<std::vector<Point>> contours;
contours.push_back(pts);
drawContours(bg, contours, -1, Scalar(255, 0, 255), 2);
imshow("Draw_polygon", bg);
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt