import json
import os
def convert_labelme_to_yolo(json_path, txt_path, label_dict):
with open(json_path, 'r') as file:
data = json.load(file)
image_width = data['imageWidth']
image_height = data['imageHeight']
with open(txt_path, 'w') as file:
for shape in data['shapes']:
label = shape['label']
points = shape['points']
x_min, y_min = points[0]
x_max, y_max = points[1]
x_center = (x_min + x_max) / 2 / image_width
y_center = (y_min + y_max) / 2 / image_height
width = (x_max - x_min) / image_width
height = (y_max - y_min) / image_height
class_id = label_dict[label]
file.write(f"{class_id} {x_center:.6f} {y_center:.6f} {width:.6f} {height:.6f}\n")
def batch_convert(input_folder, out
lableme的 json (矩形框标注)转换为yolo 格式的txt --- (类别 x,y,w,h形式)
于 2024-04-16 20:16:04 首次发布