如何使用cv2.drawContours
从numpy点数组绘制填充轮廓
由于某些原因,此代码绘制单个点而不填充轮廓:
ctr = np.array(pts).reshape((-1, 1, 2)).astype(np.int32)
mask = cv2.drawContours(mask, ctr, contourIdx=-1, color=1, thickness=-1)
使用skimage我可以做到:
from skimage.draw import polygon
mask = mask.astype(np.uint8)
rr, cc = polygon(pts[:, 1], pts[:, 0], mask.shape)
mask[rr, cc] = 1
mask = mask.astype(np.float32)