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:

  • Grab image from webcam (and turn into grayscale obviously)
  • Run it through a threshold filter (using THRESH_TO_ZERO mode, where it zeros out any pixels BELOW the threshold value).
  • blur the image
  • run it through an erosion filter
  • run it through a Canny edge detector
  • finally, take this processed image and find the lines using Probabilistic Hough Transform HoughLinesP
  • Should I change the sequence of the filters?

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

    Also, here is a sample image: 原始图像

    The results I'm getting: with canny 与canny WITHOUT canny (slightly tweaked parameters) 这次不行

    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: 有用!


    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.


    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.


    I was using Canny for indoor images, but for outdoor I find more suitable the Laplace filter and Sobel filter, than apply Probabilistic Hough line Transform (PHT).

    If u want to thicker your lines, you should try the Sobel operator after Laplace and finally the PHT. If your image is too nosy it might get worse.

    链接地址: http://www.djcxy.com/p/79632.html

    上一篇: Android阈值图像处理

    下一篇: 检测图像中行的一种好方法?