【问题标题】:Give contours from right to left in Opencv c++在Opencv c ++中从右到左给出轮廓
【发布时间】:2017-05-13 15:38:47
【问题描述】:

我想在opencv c++中使用"findContours"函数从右到左的轮廓打印轮廓的中心。当我打印中心时,我看到轮廓没有特定的顺序。 有没有办法在opencv c++中实现对轮廓的排序?

【问题讨论】:

  • 按照你想要的方式对轮廓中心进行排序,然后打印出来。
  • @ZdaR,我想知道是否可以使用“findContours”功能或其他功能的选项自动工作..??
  • @ZdaR,我在 c++ 和 opencv 方面很早。我怎样才能用它们的中心对轮廓进行排序??
  • 将轮廓中心存储在 std::vector 中并对其进行排序。
  • @narges 在 C++ 中对事物进行排序的问题和答案肯定有数百甚至数千个。做一些研究,然后想出一种方法如何在你的特定环境中应用你学到的东西。尝试实现你的算法,测试它,调试它,当你真的陷入困境时,就你遇到的问题提出一个具体的问题,展示相关的代码等。你是一门语言的新手或图书馆只是意味着您需要更多地练习上述内容,才能获得这种经验。

标签: c++ opencv opencv-contour


【解决方案1】:

你可以使用:

// 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);
    }
};

【讨论】:

    猜你喜欢
    • 2015-01-24
    • 1970-01-01
    • 2014-07-12
    • 2022-09-24
    • 2021-08-08
    • 2016-12-12
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多