2

I have the following image, which represents a path. enter image description here

I want to apply an algorithm called HoughLines(P) on it. This algorithm should detect lines and coordinates. But first I need to make the path thinner for it to be valid input for houghlinesp.

The output that I want is this:

enter image description here

I tried 'thinning' and 'skeletonizing' algorithms from python's scikit learn library. I will show the results below, but in the bottom of the images the output is not what I expected. I see that lee's skeletonize method produces a result that comes most close to my desired output, but its not good enough yet. Are there different variations of skeletonizing, thinning or any other algorithms that can produce the output that I want?

from skimage.morphology import skeletonize, thin

thinned = thin(thresholded)

enter image description here

skeleton = skeletonize(thresholded)

enter image description here

skeleton_lee = skeletonize(thresholded, method='lee')

enter image description here

Dirk
  • 95
  • 1
  • 8

1 Answers1

3

thinning/skeletonization won't work and neither will a hough transform for lines. not on that picture.

consider a perspective transform to warp your image into a top-down view. in that view, the above mentioned methods might work, or you could use something else that might have more success.

you define the four corners of a rectangle in your top-down view and the four corners of a rectangle with equal proportions on the ground in your camera view. then OpenCV's getPerspectiveTransform and warpPerspective do the rest.

edit: manual perspective warp in image editor. red lines are auxiliary. obviously not perfect because enormous perspective distortion.

manual perspective warp in image editor

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36