OpenCV的 - 寻找轮廓终点? [英] OpenCV - Finding contour end points?

查看:181
本文介绍了OpenCV的 - 寻找轮廓终点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来获得从Canny边缘检测提取的薄轮廓的端点。我想知道这是有可能与一些内置的方式。我打算在走过轮廓找到这两个点与彼此(仅沿轮廓移动)的最大距离,但是,如果一个方法已经存在容易得多。我看到cvarcLength的存在是为了得到一个轮廓的周长,因此它可能会有一个内置的方式来实现这一目标。是它是某些信息可以关于端点是已知的以这样的方式排序的等高线内的点?任何其他的想法?谢谢了!

I'm looking for a way to get the end points of a thin contour extracted from a Canny edge detection. I was wondering is this is possible with some built-in way. I would plan on walking through the contour to find the two points with the largest distance from each other (moving only along the contour), but it would be much easier if a way already exists. I see that cvarcLength exists to get the perimeter of a contour, so it's possible there would be a built-in way to achieve this. Is it are the points within a contour ordered in such a way that some information can be known about the end points? Any other ideas? Thank you much!

推荐答案

我一直在寻找同样的功能,我看<一个href=\"http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=houghlinesp#houghlinesp\"相对=nofollow> HoughLinesP 有终点,因为线未使用轮廓。我使用findContours但是让我发现这是有帮助的这样下面的轮廓和比拿第一和最后一个点作为起点和终点订购点。

I was looking for the same function, I see HoughLinesP has end points since lines are used not contours. I am using findContours however so I found it was helpful to order the points in the contours like this below and than take the first and last points as the start and end points.

struct contoursCmpY {
    bool operator()(const Point &a,const Point &b) const {
        if (a.y == b.y)
            return a.x < b.x;

        return a.y < b.y;
    }
} contoursCmpY_;

vector<Point> cont;
cont.push_back(Point(194,72));
cont.push_back(Point(253,14));
cont.push_back(Point(293,76));
cont.push_back(Point(245,125));

std::sort(cont.begin(),cont.end(), contoursCmpY_);

int size = cont.size();
printf("start Point x=%d,y=%d end Point x=%d,y=%d", cont[0].x, cont[0].y, cont[size].x, cont[size].y);

这篇关于OpenCV的 - 寻找轮廓终点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆