Choosing Lines From Hough Lines

IllSc picture IllSc · Aug 14, 2014 · Viewed 9.6k times · Source

I'm using Hough Lines to do corner detection for this image. i plan to find the intersection of the lines as the corner. This is the image. enter image description here

Unfortunately, Hough return lots of lines for each line I expect enter image description here

How do I tune the Hough Lines so there is only four lines each corresponds to actual line on the image?

Answer

HugoRune picture HugoRune · Aug 14, 2014

OpenCVs hough transform really could use some better Non-Maximum Suppression. Without that, you get this phenomenon of duplicate lines. Unfortunately I know of no easy way to tune that, besides reimplementing your own hough transform. (Which is a valid option. Hough transform is fairly simple)

Fortunately it is easy to fix in post-processing:

For the non-probabilistic hough transform, OpenCv will return the lines in order of their confidence, with the strongest line first. So simply take the first four lines that differ strongly in either rho or theta.

  • so, add the first line found by HoughLines into a new List: strong_lines
  • for each line found by HoughLines:
    • test whether its rho and theta are close to any strong_line (e.g. rho is within 50 pixels and theta is within 10° of the other line)
    • if not, put it into the list of strong_lines
    • if you have found 4 strong_lines, break