如何在c++中初始化OpenCV中的轮廓

How to initialize contour in OpenCV in C++

本文关键字:OpenCV 轮廓 初始化 c++      更新时间:2023-10-16

我想在0

中使用drawContours函数
 vector<vector<Point> > contours;

如何将以下(x,y)分配给变量轮廓?

x = [194, 253, 293, 245]
y = [72, 14, 76, 125]
有谁能帮我吗?

在c++ 11中,你可以很容易地初始化你的contours向量:

vector<vector<Point>> contours = {{{194, 72}, {253, 14}, {293, 76}, {245, 125}}};

注意contours是轮廓的vector,其中每个轮廓都是vector<Point>。这是一个包含点的容器

这段代码能帮到你吗?

vector<Point> firstContour;
firstContour.push_back(Point(194,72));
firstContour.push_back(Point(253,14));
firstContour.push_back(Point(293,76));
firstContour.push_back(Point(245,125));
contours.push_back(firstContour);