def mask_using_contours(img, contours):
"""
Return a copy of the supplied image, where all regions outside the supplied contours have been masked to white.
Args:
img (np.ndarray): the original image
contours (list[np.ndarray]): a list of contours to use when masking
Returns:
np.ndarray: the masked image
"""
img = img.copy()
mask = np.zeros(img.shape, np.uint8)
cv2.drawContours(mask, contours, contourIdx=-1, color=255, thickness=-1)
img[np.where(mask == 0)] = 255
return img
评论列表
文章目录