OpenCV cv2.fillPoly vs. cv2.fillConvexPoly: expected data type for array of polygon vertices?

前端 未结 1 1943
清酒与你
清酒与你 2020-12-28 11:34

I have the following code:

import cv2
import numpy

ar = numpy.zeros((10,10))
triangle = numpy.array([ [1,3], [4,8], [1,9] ], numpy.int32)

相关标签:
1条回答
  • 2020-12-28 12:15

    cv2.fillPoly and cv2.fillConvexPoly use different data types for their point arrays, because fillConvexPoly draws only one polygon and fillPoly draws a (python) list of them. Thus,

    cv2.fillConvexPoly(ar, triangle, 1)
    cv2.fillPoly(ar, [triangle], 1)
    

    are the correct ways to call these two methods. If you had square and hexagon point arrays, you could use

    cv2.fillPoly(ar, [triangle, square, hexagon], 1)
    

    to draw all three.

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