opencv - What does the python interface to opencv2.fillPoly want as input? -
i'm trying draw polygon using python interface opencv, cv2. i've created empty image, 640x480 numpy array. have list of polygons (four point quadrilaterals) want draw on image, however, can't seem formate right instruct cv2 quadrilaterals should be, , keep getting error:
opencv error: assertion failed (points.checkvector(2, cv_32s) >= 0) in fillconvexpoly, file .../opencv-2.4.0/modules/core/src/drawing.cpp, line 2017 my code consists of following:
binary_image = np.zeros(image.shape,dtype='int8') rect in expected: print(np.array(rect['boundary'])) cv2.fillconvexpoly(binary_image, np.array(rect['boundary']), 255) fig = pyplot.figure(figsize=(16, 14)) ax = fig.add_subplot(111) ax.imshow(binary_image) pyplot.show() where list of rects in expected has 'boundary' containing value of list of (x,y) points. code prints:
[[ 91 233] [419 227] [410 324] [ 94 349]] i figured list of points polygon, apparently list has invalid points.checkvector, whatever is. google search error turned nothing useful.
the assertionerror telling opencv wants signed, 32-bit integer. array of polygon points should have particular data type (e.g. points = numpy.array(a,dtype='int32') ). cast function call (i.e. my_array.astype('int32') ) or friend put once...
" changing
cv2.fillconvexpoly(binary_image, np.array(rect['boundary']), 255) to
cv2.fillconvexpoly(binary_image, np.array(rect['boundary'], 'int32'), 255) "
Not working yet
ReplyDelete