def get_patches(segment_arr):
ret = []
im = segment_arr.astype(np.uint8)*255
contours = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
hulls = [cv2.convexHull(cont) for cont in contours[0]]
for contour_idx in xrange(len(hulls)):
cimg = np.zeros_like(im)
cv2.drawContours(cimg, hulls, contour_idx, color=255, thickness=-1)
pts = np.array(np.where(cimg == 255)).T
ret.append(pts)
return ret
评论列表
文章目录