如何在OpenCV中测试线的接近度(霍夫变换) [英] How to test proximity of lines (Hough transform) in OpenCV

查看:93
本文介绍了如何在OpenCV中测试线的接近度(霍夫变换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是上一个问题的后续内容.)

我能够成功使用OpenCV/Hough变换检测图片中的线条(扫描的文本);起初它会检测很多行(每行文本至少一行),但是通过反复试验来调整阈值"参数,现在它仅检测实际"行.

I was able to successfully use OpenCV / Hough transforms to detect lines in pictures (scanned text); at first it would detect many many lines (at least one line per line of text), but by adjusting the 'threshold' parameter via trial-and-error, it now only detects "real" lines.

(阈值"参数取决于图像大小,如果必须处理不同分辨率的图像,这是一个问题,但这又是另一回事了.)

(The 'threshold' parameter is dependant on image size, which is a bit of a problem if one has to deal with images of different resolutions, but that's another story).

我的问题是,霍夫变换有时会检测到两行,而其中只有一行;这两条线彼此非常接近,并且(显然)是平行的.

My problem is that the Hough transform sometimes detects two lines where there is only one; those two lines are very near one another and (apparently) parallel.

=>如何识别两条线几乎平行且彼此非常接近? (这样我只能保留一个).

=> How can I identify that two lines are almost parallel and very near one another? (so that I can keep only one).

推荐答案

如果使用标准或多尺度hough,则最终将以极坐标表示直线的rho和theta坐标. Rho是到原点的距离,θ通常是检测到的线和Y轴之间的角度.在不研究opencv中的hough变换的细节的情况下,这是这些坐标中的一般规则:在以下情况下,两条线将几乎平行且彼此非常接近: -它们的theta几乎相同,而rhos几乎相同 或者 -它们的theta相距180度,而其rhos彼此相距负数

If you use the standard or multiscale hough, you will end up with the rho and theta coordinates of the lines in polar coordinates. Rho is the distance to the origin, and theta is normally the angle between the detected line and the Y axis. Without looking into the details of the hough transform in opencv, this is a general rule in those coordinates: two lines will be almost parallel and very near one another when: - their thetas are nearly identical AND their rhos are nearly identical OR - their thetas are near 180 degrees apart AND their rhos are near each other's negative

我希望这是有道理的.

这篇关于如何在OpenCV中测试线的接近度(霍夫变换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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