def extract_black_contours(img):
"""
Extract contours for black objects on a white background.
Args:
img (np.ndarray): the (black and white?) image
Returns:
list[np.ndarray]: the contours
"""
img_inverted = 255 - img
_, contours, _ = cv2.findContours(img_inverted, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_SIMPLE)
return contours
# TODO: A ContourGroups class would make this cleaner
评论列表
文章目录