OpenCV cv2.fillPoly与cv2.fillConvexPoly:多边形顶点数组的预期数据类型? [英] OpenCV cv2.fillPoly vs. cv2.fillConvexPoly: expected data type for array of polygon vertices?
问题描述
我有以下代码:
import cv2
import numpy
ar = numpy.zeros((10,10))
triangle = numpy.array([ [1,3], [4,8], [1,9] ], numpy.int32)
如果我像这样使用cv2.fillConvexPoly:
If I use cv2.fillConvexPoly like so:
cv2.fillConvexPoly(ar, triangle, 1)
则结果如预期.但是,如果我尝试:
then the results are as expected. If, however, I try:
cv2.fillPoly(ar, triangle, 1)
然后我得到一个失败的断言.这似乎与断言相同,如果我对不具有dtype numpy.int32
的cv2.fillConvexPoly
使用numpy数组,则该断言将失败. cv2.fillPoly
和cv2.fillConvexPoly
的第二个参数期望不同的数据类型吗?如果是这样,我应该为cv2.fillPoly
使用什么?
then I get a failed assertion. This seems to be identical to the assertion that fails if I use a numpy array for cv2.fillConvexPoly
that does not have dtype numpy.int32
. Do cv2.fillPoly
and cv2.fillConvexPoly
expect different data types for their second argument? If so, what should I be using for cv2.fillPoly
?
推荐答案
cv2.fillPoly
和cv2.fillConvexPoly
为它们的点数组使用不同的数据类型,因为fillConvexPoly
仅绘制一个多边形,而fillPoly
绘制一个(python)他们的名单.因此,
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)
是调用这两种方法的正确方法.如果您有square
和hexagon
点数组,则可以使用
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)
绘制所有三个.
这篇关于OpenCV cv2.fillPoly与cv2.fillConvexPoly:多边形顶点数组的预期数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!