def _find_hull_defects(self, segment):
# Use cv2 findContours function to find all the contours in segmented img
contours, hierarchy = cv2.findContours(segment, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# assume largest contour is the one of interest
max_contour = max(contours, key=cv2.contourArea)
epsilon = 0.01*cv2.arcLength(max_contour, True)
max_contour = cv2.approxPolyDP(max_contour, epsilon, True)
# determine convex hull & convexity defects of the hull
hull = cv2.convexHull(max_contour, returnPoints=False)
defects = cv2.convexityDefects(max_contour, hull)
return (max_contour, defects)
评论列表
文章目录