如何在OpenCV中找到线的端点? [英] How to find endpoints of lines in OpenCV?

查看:781
本文介绍了如何在OpenCV中找到线的端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张由线条组成的图像;如何使用OpenCV查找端点?

I have an image made up of lines; how can I find the endpoints with OpenCV?

线条大约20像素宽.它们旋转,分支并可以成一定角度(尽管大部分是水平和垂直的).请注意,霍夫行不通,因为我的线条不直. (也许这使它们具有轮廓?)

The lines are about 20 pixels wide. They turn, branch, and can be at angles (although mostly horizontal and vertical). Note that Hough won't work because my lines aren't straight. (Maybe that makes them contours?)

我查看了此答案,但它找到了极端点,而不是端点.我看着,但是我认为goodFeaturesToTrack()也将增加优势.尽管OpenCV似乎没有一个稀疏算法,但也许可以使用它?

I looked at this answer but it finds extreme points, not endpoints. I looked at this, but I think goodFeaturesToTrack() will pick up corners too. Maybe use a thinning algorithm, although OpenCV doesn't seem to have one?

下图显示了样品输入(蓝色)和所需的终点(品红色).

The image below shows sample input (blue) and the desired endpoints (magenta).

推荐答案

您可以按照

You can create a morphological skeleton (thinning algorithm which you talked about) as described here, my implementation of this is here. Then you can traverse the skeleton(s) and just look for the end of it in every way.

这篇关于如何在OpenCV中找到线的端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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