Description: This code is a section of the overall code. The main function is to convert mask_info (bool type two-dimensional vector) into segmentation that needs to be labeled.
contours, hierarchy = cv2.findContours(mask_info.astype(np.uint8),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
xy_list = []
for contour in contours:
xy = contour[:,0,:].ravel().tolist()
xy_list.append(xy)
obj_info['area'] = (x2-x1)*(y2-y1)
obj_info['bbox'] = [float(x1), float(y1), float(x2-x1), float(y2-y1)]
obj_info['cate'] = cate
obj_info['segmentation'] = xy_list
Reference article: Blog