# labels with warnings.catch_warnings(): # ignore the warning information when the file is empty warnings.simplefilter("ignore") labels = np.loadtxt(file)
targets = np.zeros((len(labels), 5)) if labels.size == 0: continue if labels.ndim == 1: labels = labels[None] # part2: annotations information for label in labels: target_info = { "segmentation" : [], "category_id" : int(label[0]), "image_id" : id, "id" : ann_id, "area" : round((label[3]-label[1])*(label[4]-label[2]), 6), "bbox" : xyxy2xywh(label, (H,W)), "iscrowd" : 0, } ann_id += 1 label_json["annotations"].append(target_info) # save the labels in a json file withopen(json_path, 'w') as json_f: json.dump(label_json, json_f)
polygon = [] for point in contour: polygon.extend( [point[0][0], point[0][1]] ) # get area area = cv2.contourArea(contour) # get bounding box bbox = cv2.boundingRect(contour)