Closing a contour curve in OpenCV

前端 未结 2 1711
無奈伤痛
無奈伤痛 2020-12-31 08:45

I\'m using OpenCV (Canny + findCountours) to find external contours of objects. The curve drawn is typically almost, but not entirely, closed. I\'d like to close it - to f

相关标签:
2条回答
  • 2020-12-31 09:26

    A little late, but I just had to deal with this myself. If you perform an opening operation (erosion followed by dilation) prior to the Canny edge detection, the edges you detect should be more continuous, resulting in better contours. This method appears to be fairly robust. I mentioned this in another post and posted a code sample as part of a recent question.

    0 讨论(0)
  • 2020-12-31 09:50

    Using PolyLine method to draw contours

    cv2.PolyLine(img, points, is_closed=True, 255, thickness=1, lineType=8, shift=0)
    

    Read the docs for further details: http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html

    Mark answered if it resolved your problem. If not then let me know.

    0 讨论(0)
提交回复
热议问题