如何在OpenCV 2.3.1中使用等高线? 我最近从OpenCV的C接口改为C++接口。在C接口中,有很多东西似乎不存在于C++中。是否有人知道这些问题的解决方案:

如何在OpenCV 2.3.1中使用等高线? 我最近从OpenCV的C接口改为C++接口。在C接口中,有很多东西似乎不存在于C++中。是否有人知道这些问题的解决方案:,c++,opencv,vector,contour,C++,Opencv,Vector,Contour,1) 在C界面中有一个称为轮廓扫描仪的对象。它被用来一个接一个地查找图像中的轮廓。在C++中我该怎么做?我不想一次找到所有的轮廓,而是想一次找到一个 < > 2)在C 中,CvSeq 用于表示等高线,而在C++ 矢量< /代码>中使用。在C中,我可以使用h\u next访问下一个轮廓。什么是C++等价于 HyNeX?< /P> < P>我不确定你是否能一次获得轮廓。但是如果你有一个向量,你可以如下迭代每个轮廓: using namespace std; vector<vector<

1) 在C界面中有一个称为轮廓扫描仪的对象。它被用来一个接一个地查找图像中的轮廓。在C++中我该怎么做?我不想一次找到所有的轮廓,而是想一次找到一个


< > 2)在C <代码>中,CvSeq </代码>用于表示等高线,而在C++ <代码>矢量< /代码>中使用。在C中,我可以使用
h\u next
访问下一个轮廓。什么是C++等价于<代码> HyNeX?< /P> < P>我不确定你是否能一次获得轮廓。但是如果你有一个
向量
,你可以如下迭代每个轮廓:

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
   }
}

+天哪!很难跟上OpenCV中API的变化,对吧?!
vector<vector<Point> >::iterator contour = contours.begin();
vector<vector<Point> >::iterator next = contour+1; // behavior like h_next