OpenCV cv2.fillPoly与cv2.fillConvexPoly:多边形顶点数组的预期数据类型?

wil*_*wil 8 python opencv

我有以下代码:

import cv2
import numpy

ar = numpy.zeros((10,10))
triangle = numpy.array([ [1,3], [4,8], [1,9] ], numpy.int32)
Run Code Online (Sandbox Code Playgroud)

如果我像这样使用cv2.fillConvexPoly:

cv2.fillConvexPoly(ar, triangle, 1)
Run Code Online (Sandbox Code Playgroud)

然后结果如预期.但是,如果我尝试:

cv2.fillPoly(ar, triangle, 1)
Run Code Online (Sandbox Code Playgroud)

然后我得到一个失败的断言.这似乎是相同的,如果我使用numpy的数组失败的说法cv2.fillConvexPoly不具有D型numpy.int32.为第二个参数做cv2.fillPolycv2.fillConvexPoly期望不同的数据类型?如果是这样,我应该用cv2.fillPoly什么?

wil*_*wil 22

cv2.fillPolycv2.fillConvexPoly为其点数组使用不同的数据类型,因为fillConvexPoly只绘制一个多边形并fillPoly绘制它们的(python)列表.从而,

cv2.fillConvexPoly(ar, triangle, 1)
cv2.fillPoly(ar, [triangle], 1)
Run Code Online (Sandbox Code Playgroud)

是调用这两种方法的正确方法.如果你有squarehexagon点数组,你可以使用

cv2.fillPoly(ar, [triangle, square, hexagon], 1)
Run Code Online (Sandbox Code Playgroud)

画出这三个.