簡體   English   中英

在 Opencv c++ 中從右到左給出輪廓

[英]Give contours from right to left in Opencv c++

我想在 opencv c++ 中使用"findContours" function 從右到左的輪廓打印輪廓中心。 當我打印中心時,我看到輪廓沒有特定的順序。 有沒有辦法在 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 ” function 是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM