Something is off. fillPoly documentation says "Fills the area bounded by one or more polygons." and "pts Array of polygons where each polygon is represented as an array of points."
But the following code is drawing all 5 polygons, and filling the bottom which is not one of the polygons at all!
Is this me? Or is it a bug?
import cv2
import numpy as np
from numpy import int32, array
img = np.zeros((720, 1280))
pnts = [array([[242, 387], [122, 478], [144, 228], [246, 139], [242, 387]], dtype=int32), # top
array([[242, 387], [511, 585], [460, 377], [246, 139], [242, 387]], dtype=int32), # front
array([[242, 387], [511, 585], [390, 633], [122, 478], [242, 387]], dtype=int32), # left side
array([[246, 139], [460, 377], [360, 427], [144, 228], [246, 139]], dtype=int32), # right side
array([[144, 228], [360, 427], [390, 633], [122, 478], [144, 228]], dtype=int32)] # back
cv2.fillPoly(img, pnts, color=[255,255,255])
cv2.imshow("img", img)
cv2.waitKey()
Workaround:
for polygon in pnts:
cv2.fillPoly(img, [polygon], color=[255,255,255])
