如何在 OpenCV 中测试线条的接近度(霍夫变换)

发布于 2024-08-03 22:06:07 字数 345 浏览 2 评论 0原文

(这是上一个问题的后续问题)。

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

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

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

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

(This is a follow-up from this previous question).

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼性发作 2024-08-10 22:06:07

如果您使用标准或多尺度霍夫,您最终将得到极坐标中线的 rho 和 theta 坐标。 Rho 是到原点的距离,theta 通常是检测到的线与 Y 轴之间的角度。在不研究 opencv 中霍夫变换的细节的情况下,这是这些坐标中的一般规则:当出现以下情况时,两条线将几乎平行并且彼此非常接近:
- 它们的 theta 几乎相同,并且它们的 rho 几乎相同
或者
- 他们的 theta 相距接近 180 度,并且他们的 rho 接近彼此的负值,

我希望这是有道理的。

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

I hope that makes sense.

感情洁癖 2024-08-10 22:06:07

有趣的是,theta 是直线和 y 轴之间的角度。

一般来说,rho 和 theta 值可视化为从 x 轴到垂直于所讨论的线的线的角度。 rho 就是这条垂直线的长度。因此,theta = 90 且 rho = 20 表示距离原点向上 20 个像素的水平线。
霍夫变换问题上显示了一张漂亮的图片

That's interesting about the theta being the angle between the line and the y-axis.

Generally, the rho and theta values are visualized as being the angle from the x-axis to the line perpendicular to the line in question. The rho is then the length of this perpendicular line. Thus, a theta = 90 and rho = 20 would mean a horizontal line 20 pixels up from the origin.
A nice image is shown on Hough Transform question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文