【问题标题】:how to read data stored in output of findcontour function in opencv using c++如何使用c ++读取存储在opencv中findcontour函数输出中的数据
【发布时间】:2015-08-18 22:35:02
【问题描述】:
我想使用 find contour 和 drawcontour 功能在二值图像中标记对象。
我也想知道findcontour函数的输出数组中存储了哪些数据。
另外,有没有其他合适的方法可以做到以上几点?
【问题讨论】:
-
findContours() 为您提供vector<vector<Point>>,即 - 对于找到的每个轮廓,都有一个船体点列表。如果您想要标签,请查看connectedComponents
标签:
c++
opencv
components
labeling
【解决方案1】:
@berak 的评论已经回答了。我将添加输出的外观部分。考虑一个 35x62 的图像,其 5 倍放大版本如下。该图像有 6 个斑点或对象,每个斑点或对象都有相应的轮廓。
上面的图像存储在 Mat 对象im 中。 findContour 被应用为
cv::findContours(im.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
findContour 的输出是一个vector<vector<Point>> 对象contours,它看起来像:
所以,它有 6 个元素,每个元素对应一个轮廓。我们以contours[0] 为例。它看起来像:
contours[0] 有五个元素,每个元素存储形成轮廓的像素的坐标。