Creating your own contour in opencv using python

前端 未结 4 599
长情又很酷
长情又很酷 2021-02-07 07:00

I have a set of boundary points of an object.

I want to draw it using opencv as contour.

I have no idea that how to convert my points to contour representation.

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 07:29

    By looking at the format of the contours I would think something like this should be sufficient:

    contours = [numpy.array([[1,1],[10,50],[50,50]], dtype=numpy.int32) , numpy.array([[99,99],[99,60],[60,99]], dtype=numpy.int32)]
    

    This small program gives an running example:

    import numpy
    import cv2
    
    contours = [numpy.array([[1,1],[10,50],[50,50]], dtype=numpy.int32) , numpy.array([[99,99],[99,60],[60,99]], dtype=numpy.int32)]
    
    drawing = numpy.zeros([100, 100],numpy.uint8)
    for cnt in contours:
        cv2.drawContours(drawing,[cnt],0,(255,255,255),2)
    
    cv2.imshow('output',drawing)
    cv2.waitKey(0)
    

提交回复
热议问题