Question

I have been working with houghlines in OpenCV and I cant seem to get a more accurate line reading, sometimes there are two duplicate lines on top of each other. I have looked at tutorial on the opencv website but it gives a similar result.

Was it helpful?

Solution

To remove those duplicate lines, there are two things that may help you:

  1. Double edges may appear that may lead to duplicate lines. A sequence of blurring/dilating the input image would solve these issues.
  2. Close lines that have almost same slope can be removed by using lower angle resolutions for the theta argument of Hough Line method. For example using π/180 would result in finding lines that differ only by one degree in their slope. You may use 5*π/180 to find lines in 5 degree resolution.

As an example, the following lines are detected by using the raw image and a 1-degree resolution: triple

After a bit of blurring and using a 3-degree resolution you can get a result like the following: fixed

By changing the threshold, you can get more or less lines.
About fitting curves you pointed in the comments section, yes you can fit curves, but not with hough lines method. You need to find a parametric definition of that shape and try to run the voting procedure in hough transform yourself. The only other shape that opencv helps you to find is circle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top