How to find endpoints of lines in OpenCV?

前端 未结 4 742
滥情空心
滥情空心 2021-01-19 00:42

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 mos

4条回答
  •  粉色の甜心
    2021-01-19 01:25

    If your endpoints are always either horizontal or vertical you can also try to convolve the image with a simple kernel - square (side should be equal to your line width) with background (width should be equal to minimal distance between neighboring endpoints). Color (or intensity) of square and background should match those on your images.

    In this case endpoints would "match" the kernel along 3 "sides", line segments and corners along "2 sides", other shapes should have a weaker response. By thresholding response appropriately you should be able to get endpoint locations.

    This approach should be simpler and faster (if implemented appropriately) than the one you settled on currently, but it may have some quirks depending on the input. Unfortunately, I don't have time to try implementing it.

提交回复
热议问题