OpenCV cv2.fillPoly与cv2.fillConvexPoly:多边形顶点数组的预期数据类型? [英] OpenCV cv2.fillPoly vs. cv2.fillConvexPoly: expected data type for array of polygon vertices?

查看:859
本文介绍了OpenCV cv2.fillPoly与cv2.fillConvexPoly:多边形顶点数组的预期数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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.int32cv2.fillConvexPoly使用numpy数组,则该断言将失败. cv2.fillPolycv2.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.fillPolycv2.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)

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆