Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find endpoints of lines in OpenCV?

I have an image made up of lines; how can I find the endpoints with OpenCV?

The lines are about 20 pixels wide. They turn, branch, and can be at angles (although mostly horizontal and vertical). Note that Hough won't work because my lines aren't straight. (Maybe that makes them contours?)

I looked at this answer but it finds extreme points, not endpoints. I looked at this, but I think goodFeaturesToTrack() will pick up corners too. Maybe use a thinning algorithm, although OpenCV doesn't seem to have one?

The image below shows sample input (blue) and the desired endpoints (magenta).

Lines with endpoints marked

like image 409
Ken Shirriff Avatar asked Feb 14 '17 20:02

Ken Shirriff


1 Answers

I speak Chinese, while my English is poor.

So I just post my core steps.

A general way to find endpoints of lines is:

  1. Binary the gray image.
  2. Find the skeleton of the binary image.
  3. Do hit-miss operation (all end points) or goodFeaturesToTrack(all corners include endpoints) on the skeleton.

Notice:

You should select a good skeleton method to make sure that the endpoints wouldn't shrink(while my example does shrink).


This is the result.

enter image description here

This is a demo using hit-miss to find special points. enter image description here

like image 170
Kinght 金 Avatar answered Sep 27 '22 23:09

Kinght 金