[英]How to use Contours in OpenCV 2.3.1?
我最近从使用C接口改为OpenCV中的C ++接口。 在C接口中,C ++中似乎不存在各种各样的东西。 有谁知道这些问题的解决方案:
1)在C接口中有一个名为Contour Scanner的对象。 它被用于逐个查找图像中的轮廓。 我将如何在C ++中执行此操作? 我不想一次找到所有轮廓,而是希望一次找到一个。
2)在C中, CvSeq
用于表示轮廓,但是在C ++中使用vector <vector<Point> >
。 在CI中,可以使用h_next
访问下一个轮廓。 什么是C ++相当于h_next
?
我不确定你是否可以一次获得一个轮廓。 但是如果你有一个vector<vector<Point> >
你可以迭代每个轮廓,如下所示:
using namespace std;
vector<vector<Point> > contours;
// use findContours or other function to populate
for(size_t i=0; i<contours.size(); i++) {
// use contours[i] for the current contour
for(size_t j=0; j<contours[i].size(); j++) {
// use contours[i][j] for current point
}
}
// Or use an iterator
vector<vector<Point> >::iterator contour = contours.begin(); // const_iterator if you do not plan on modifying the contour
for(; contour != contours.end(); ++contour) {
// use *contour for current contour
vector<Point>::iterator point = contour->begin(); // again, use const_iterator if you do not plan on modifying the contour
for(; point != contour->end(); ++point) {
// use *point for current point
}
}
因此,为了更好地回答有关h_next
的问题。 给定迭代器, it
在vector
,下一个元素将是it+1
。 用法示例:
vector<vector<Point> >::iterator contour = contours.begin();
vector<vector<Point> >::iterator next = contour+1; // behavior like h_next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.