我想在 opencv c++ 中使用 "findContours"
函数从右到左打印轮廓中心。当我打印中心时,我看到轮廓没有特定的顺序。
有没有办法在opencv c++中实现轮廓顺序?
最佳答案
您可以使用:
// Find all the contours
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(Image, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
sort(contours.begin(), contours.end(), Right_Left_contour_sorter());
和“Right_Left_contour_sorter
”函数是:
struct Right_Left_contour_sorter // 'less' for contours
{
bool operator ()( const vector<Point>& a, const vector<Point> & b )
{
Rect ra(boundingRect(a));
Rect rb(boundingRect(b));
return (ra.x > rb.x);
}
};
关于c++ - 在 Opencv c++ 中从右到左给出轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43954947/