What does the python interface to opencv2.fillPoly want as input?
The AssertionError is telling you that OpenCV wants a signed, 32-bit integer. The array of polygon points should have that particular data type (e.g. points = numpy.array(A,dtype='int32')
). You could also just cast it for the function call (i.e. my_array.astype('int32')
) or as a friend put it once...
" Changing
cv2.fillConvexPoly(binary_image, np.array(rect['boundary']), 255)
to
cv2.fillConvexPoly(binary_image, np.array(rect['boundary'], 'int32'), 255)
"
import numpy as np
import cv2
import matplotlib.pyplot as plt
a3 = np.array( [[[10,10],[100,10],[100,100],[10,100]]], dtype=np.int32 )
im = np.zeros([240,320],dtype=np.uint8)
cv2.fillPoly( im, a3, 255 )
plt.imshow(im)
plt.show()
Check on colab.research.google.com