def find_contours(self, img):
thresh_img = self.threshold(img)
_, contours, _ = cv2.findContours(thresh_img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
result = []
for cnt in contours:
approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True)
if self.draw_approx:
cv2.drawContours(self.out, [approx], -1, self.BLUE, 2, lineType=8)
if len(approx) > 3 and len(approx) < 15:
_, _, w, h = cv2.boundingRect(approx)
if h > self.min_height and w > self.min_width:
hull = cv2.convexHull(cnt)
approx2 = cv2.approxPolyDP(hull,0.01*cv2.arcLength(hull,True),True)
if self.draw_approx2:
cv2.drawContours(self.out, [approx2], -1, self.GREEN, 2, lineType=8)
result.append(approx2)
return result
评论列表
文章目录