opencv笔记15-多边形的填充与绘制

多边形的填充与绘制

#include
#include
#include

using namespace std;
using namespace cv;

//多边形的填充与绘制
void  polyline_draw_demo()
{
	//初始化画布
	Mat canvas = 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);

	//vector存储点的集合
	vector<Point>pts;
	pts.push_back(p1);
	pts.push_back(p2);
	pts.push_back(p3);
	pts.push_back(p4);
	pts.push_back(p5);

	填充多边形
	//fillPoly(canvas, pts, Scalar(255, 255, 0), 8, 0);

	绘制多边形
	//polylines(canvas, pts, true, Scalar(0, 255, 0), 2, LINE_AA, 0);

	vector<vector<Point>>contours;
	contours.push_back(pts);
	//绘制填充
	drawContours(canvas, contours, -1, Scalar(255, 0, 0), -1);

	imshow("多边形绘制", canvas);
}

int main()
{
	string path = "C:\\Users\\四明\\Pictures\\QQ图片20200608155343.jpg";
	Mat img = imread(path);
	if (img.empty())
	{
		cout << "图片加载失败!" << endl;
		return -1;
	}
	namedWindow("image", WINDOW_FREERATIO);
	imshow("image", img);
	polyline_draw_demo();
	waitKey(0);
	destroyAllWindows();
	return 0;
}

你可能感兴趣的:(opencv笔记,笔记,opencv,c++)