Opencv Imgproc.HoughLines()调整长度参数

时间:2014-01-21 18:13:47

标签: java opencv computer-vision hough-transform

- 请参阅下面的更新/答案。用户错误! -

我正在尝试了解如何在Imgproc.HoughLines()中设置参数以查找较短的行。我尝试过这样的东西根本不起作用:

Imgproc.HoughLines(matSrc, matLines, 1, Math.PI / 180, houghThreshCurrent, 25, 10);

我已经为最后两个参数尝试了几个值,但似乎都没有 - 它找不到任何行。但是,使用没有最后两个参数的方法版本可以很好地找到我想要的线条,而不管阈值有多低都不是短线条。

这是最后两个参数的文档:

srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho. The coarse accumulator distance resolution is rho and the accurate accumulator resolution is rho/srn. If both srn=0 and stn=0, the classical Hough transform is used. Otherwise, both these parameters should be positive.
stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta.

有人可以翻译或提供示例值吗? :)

我也尝试了概率版HoughLinesP()。它对我的用例似乎不太好用。另一种选择是将我的图像缩放到更大的尺寸,如果我无法使线距参数工作,则默认的HoughLines()可以工作。


答案:我的问题是我没有意识到HoughLinesP()返回的Mat格式与HoughLines()返回的格式不同。当它们已经在XY坐标中时,我正在从极坐标转换HoughLinesP()的结果!事实证明,HoughLinesP()远远优于我们的需求,其参数对于调整线长度非常有用。这是帮助我查看错误方式的链接:https://dsp.stackexchange.com/questions/10467/influence-of-image-size-to-edge-detection-in-opencv

1 个答案:

答案 0 :(得分:1)

可以在这里找到一个很好的例子:http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

尝试使用CV_PI代替Math.PI?其他原因可能是因为你的门槛。尝试插入一个像50这样的值(玩数字)。最后2个值,您可以尝试将其保留为零并在插入值之前先测试它。最后2的默认值通常为零。

为什么它不起作用可能有很多原因,所以让我们慢慢找到原因。另外,在你申请霍夫之前,你做过Canny它还是什么?

希望有所帮助,让我知道我的建议是否有用和帮助(:干杯。