Reputation: 599
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)
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)
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
?
Upvotes: 13
Views: 38519
Reputation: 599
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.
Upvotes: 30