def apply(self, item, threshold):
img = item.img_mat
img[img > 0] = 255
_, contours, _ = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
valid_contours = []
for contour in contours:
max_x = contour[:, :, 0].max()
min_x = contour[:, :, 0].min()
max_y = contour[:, :, 1].max()
min_y = contour[:, :, 1].min()
if (max_x - min_x) * (max_y - min_y) > threshold:
valid_contours.append(contour)
yield valid_contours
评论列表
文章目录