Extract lines from canny edge detection

In openCV, after applying canny edge detection, I would like to continue processing the result (show only horizontal lines, delete short lines, etc.). But the canny result is just another look. I would like to get an array of strings describing detected edges

I know the famous Hough Line Transform , but the result is not always good, so I would like to manually process the canny result. input:

enter image description here

output only canny:

enter image description here

canny output then Hough line conversion

enter image description here

This is the result of converting the Hough line (red lines) to detect the edges of the stairs. The 4th line below was not detected correctly, although canny edge detected the edge.

Any idea how to extract edges from canny image?

+7
source share
2 answers

A few things you can try to improve your results:

Apply area of ​​interest

There are some border window effects in your image. I deleted them with the region of interest, the result is an image that looks like this (I changed it until it looked right, but if you use some kind of kernel operator, the window size is probably better defined by this ROI):

enter image description here

Use standard Hough transform

It also seems that you are using the Hough probabilistic transformation. Thus, you get only line segments instead of the interpolated line. Consider the standard transformation to get the complete theoretical line (rho, theta). To do this, I got an image as shown below:

enter image description here

Here is the code snippet I used to create the strings (from the Python interface):

(mu, sigma) = cv2.meanStdDev(stairs8u) edges = cv2.Canny(stairs8u, mu - sigma, mu + sigma) lines = cv2.HoughLines(edges, 1, pi / 180, 70) 

Angle-based filter lines

You can probably filter out the bad lines using the most common linear angles and discarding outliers. This should narrow it down to the most visible steps.

Hope this helps!

+14
source

I recommend using the LSWMS method (line segment determination using weighted average shift). It is better than HT and PPHT.

See http://marcosnietoblog.wordpress.com/2012/04/28/line-segment-detection-opencv-c-source-code as well as http://www.youtube.com/watch?v=YYeX8IGOAxw

+7
source

All Articles