Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A good approach for detecting lines in an image?

I've written some code that uses OpenCV libraries to detect white lines painted on grass. I need someone's opinion on the approach I used (as I'm sure there's a much better way than mine). Also, the results I'm getting are not as good as I expected because slight variations in the image require tweaking the parameters (and I need to operate on fixed parameters).

My approach so far:

  1. Grab image from webcam (and turn into grayscale obviously)
  2. Run it through a threshold filter (using THRESH_TO_ZERO mode, where it zeros out any pixels BELOW the threshold value).
  3. blur the image
  4. run it through an erosion filter
  5. run it through a Canny edge detector
  6. finally, take this processed image and find the lines using Probabilistic Hough Transform HoughLinesP

Should I change the sequence of the filters?

P.S. I'm not too concerned about processing power; I'm running the HoughLinesP on the GPU B-)

Also, here is a sample image: original image

The results I'm getting: with canny with canny WITHOUT canny (slightly tweaked parameters) no canny this time

Any help or guidance would be appreciated! I just have no idea what to do to improve it!

UPDATE After using a really quick skeleton implementation (with TONS of blur) as per the chosen answer, I got this: it works!

like image 443
Cashew Avatar asked May 21 '13 08:05

Cashew


People also ask

Which method is used for line detection?

points and finds all the lines on which these edge points lie. The most popular line detectors are the Hough transform and convolution-based techniques.

Which mask is used to detect lines in an image?

In a convolution-based technique, the line detector operator consists of a convolution masks tuned to detect the presence of lines of a particular width n and a θ orientation. Here are the four convolution masks to detect horizontal, vertical, oblique (+45 degrees), and oblique (−45 degrees) lines in an image.

What is line detection used for?

Line detection consists of detecting alignments of points on an image of contours. The usual method for line detection is the Hough transform [Hough 1962]. Like the Fourier transform, it transposes the image from the spatial domain to another domain, where the information of interest is represented differently.

Which filter is used for line detection?

Sobel Filter This is the most common simple first order differential edge detector.


2 Answers

I would try to use a skeleton representation of the image. The problem with your canny, here, is that it basically results in two lines because of the width of the line.

Then I would apply the Hough transform on it.

like image 95
JonasVautherin Avatar answered Nov 09 '22 12:11

JonasVautherin


One possible solution is to take all the edge points that you obtain from the canny edge detection and fit a line using linear least sqaures (maybe iterative) on these points. This way you always get a single line that "best fits" the edge points. There is virtually no parametrisation involved with this method.

like image 32
Zaphod Avatar answered Nov 09 '22 12:11

Zaphod