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).
I speak Chinese, while my English is poor
.
So I just post my core steps.
A general way to find endpoints of lines is:
Binary
the gray image.skeleton
of the binary image.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.
This is a demo using hit-miss
to find special points.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With