medloh
medloh

Reputation: 969

Opencv Imgproc.HoughLines() tuning length parameters

--See update/answer below. User error!--

I'm trying to understand how to set the parameters in Imgproc.HoughLines() to find shorter lines. I've tried something like this that doesn't work at all:

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

I have tried several values for the last two parameters, but none seem to work--it finds no lines. However, using the version of the method without the last two parameters does a decent job of finding the lines I want, just not the shorter lines no matter how low the threshold is.

Here's the doc for the last two params:

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.

Could someone translate or provide example values for that? :)

I've also tried the probabalistic version, HoughLinesP(). It doesn't seem to work very well for my use case. The other option would be to scale my image to a larger size where the default HoughLines() works if I can't get the line distance parameters working.


Answer: My problem was I didn't realize the Mat returned by HoughLinesP() was in a different format than the one returned by HoughLines(). I was transforming the results from HoughLinesP() from polar coordinates when they were already in the XY coordinates! Turns out HoughLinesP() is far superior for our needs and its parameters work great for tuning line length. Here's the link that helped me see the error of my ways: https://dsp.stackexchange.com/questions/10467/influence-of-image-size-to-edge-detection-in-opencv

Upvotes: 1

Views: 6793

Answers (1)

rockinfresh
rockinfresh

Reputation: 2106

A very good example can be found here: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html

Try using CV_PI instead of Math.PI? Other reasons could be because of your threshold. Try inserting a value like 50(play around with the numbers). The last 2 values, u can try leaving it to be zero and test it first before inserting values. Default Values for the last 2 is usually zero.

There could be many reasons why its not working, so let's slowly find the cause one by one. Also, you did Canny it or something before you applied Hough right?

Hope that helps, let me know if my suggestions are useful and helped(: Cheers.

Upvotes: 1

Related Questions