How to connect broken lines in a binary image using Python/Opencv

后端 未结 3 1742
遇见更好的自我
遇见更好的自我 2020-12-05 11:44

How can I make these lines connect at the target points? The image is a result of a skeletonization process.

\"R

3条回答
  •  Happy的楠姐
    2020-12-05 12:21

    Since the image is already monochromatic, you can use morphological transformations to close broken lines.

    In case you need an example, you can find it in the documentation here: http://docs.opencv.org/2.4/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html#closing

    It works by first dilating the white areas in the image and then eroding back by the same amount. Effectively closing any holes in the white areas. More details and examples can be found here: http://docs.opencv.org/2.4/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html

    This strategy requires that the gap in the broken line is smaller than the distance between neighboring lines.

    It will not work, if the lines cross, or if the lines are too close to each other. However I think it will work quite nicely in your example.

    You can also remove the artifacts below the third line using the erode function.

提交回复
热议问题