Skip to content
Advertisement

How to merge lines after HoughLinesP?

My task is to find coordinates of lines (startX, startY, endX, endY) and rectangles (4 lines). Here is input file:enter image description here

I use the next code:

JavaScript

I get the next results: enter image description here enter image description here enter image description here

From the last image you can see big amount of small red lines.

Questions:

  1. What is the best way to merge small lines?
  2. Why there are a lot of small portions that are not detected by HoughLinesP?

Advertisement

Answer

I have finally completed the pipeline:

  1. fixed incorrect parameters (as were suggested by Dan)
  2. developed my own ‘merging line segments’ algorithm. I had bad results when I implemented TAVARES and PADILHA algorithm (as were suggested by Andrew).
  3. I have skipped Canny and got better results (as were suggested by Alexander)

Please find the code and results:

JavaScript

enter image description here

There are still 572 lines. After my “merging line segments” we have only 89 lines enter image description here

Advertisement