在 Opencv C++ 中从右到左给出轮廓
Give contours from right to left in Opencv c++
我想在 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);
}
};
我想在 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);
}
};