yolo生成labelme格式标签:
base_name= os.path.basename(file)
orgimg = cv2.imread(file) # BGR
img0 = copy.deepcopy(orgimg)
assert orgimg is not None, 'Image Not Found ' + image_path
h0, w0 = orgimg.shape[:2] # orig hw
annotation = {}
annotation['version'] ="4.5.6"
annotation['flags'] = {}
annotation['shapes'] = []
annotation['imagePath'] = base_name
annotation['imageData'] = None
annotation['imageHeight'] = h0
annotation['imageWidth'] = w0
boxes=[]
for j in range(det.size()[0]):
xywh = (xyxy2xywh(det[j, :4].view(1, 4)) / gn).view(-1).tolist()
conf = det[j, 4].cpu().numpy()
landmarks = (det[j, 5:15].view(1, 10) / gn_lks).view(-1).tolist()
class_num = det[j, 15].cpu().numpy()
orgimg = show_results(orgimg, xywh, conf, landmarks, class_num)
data={"label":'head'}
data['points']=[det[j, :2].cpu().data.numpy().tolist(),det[j, 2:4].cpu().data.numpy().tolist()]
data['group_id']=None
data['shape_type']='rectangle'
data['flags']={}
annotation['shapes'].append(data)
# json.dump(annotation, open(save_json_path, 'w'), indent=4, cls=MyEncoder) # indent=4 更加美观显示
save_json_path=json_to+'/'+base_name[:-4]+".json"
json.dump(annotation, open(save_json_path, 'w'), indent=4,cls=MyEncoder) # indent=4 更加美观显示