c++ - 在 Opencv c++ 中从右到左给出轮廓

标签 c++ opencv contour

我想在 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/

相关文章:

c++ - Qt QSpinbox 和 QPushButton 到 Arduino

python - Matplotlib 中的散点图等高线

image-processing - 有什么比 ImageMagick 更快的吗?

Matlab和OpenCV对同一幅图像计算不同的图像矩m00

opencv - 无法在XCode中链接OpenCV框架符号

ggplot2中的R绘图填充.contour()输出

Opencv contour.exe 中未处理的异常

c++ - 克隆抽象基类(不干涉派生)

C++ 字符串转换

c++ - Metal - 针对内存延迟优化 GPU 矩阵乘法