Я не уверен, что вы можете получить контуры по одному.Но если у вас есть 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