Creating your own contour in opencv using python

前端 未结 4 597
长情又很酷
长情又很酷 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:16

    To create your own contour from a python list of points L

    L=[[x1,y1],[x2,y2],[x3,y3],[x4,y4],[x5,y5],[x6,y6],[x7,y7],[x8,y8],[x9,y9],...[xn,yn]]
    

    Create a numpy array ctr from L, reshape it and force its type

    ctr = numpy.array(L).reshape((-1,1,2)).astype(numpy.int32)
    

    ctr is our new countour, let's draw it on an existing image

    cv2.drawContours(image,[ctr],0,(255,255,255),1)
    

提交回复
热议问题