将json标注文件转为txt格式
用Labelme标注图片后,需要批量转为YOLO系列模型所需的txt格式
注意,此代码仅适用矩形框标注方法的转换
import json
import os
def convert(img_size, box):
x1 = box[0]
y1 = box[1]
x2 = box[2]
y2 = box[3]
center_x = (x1 + x2) * 0.5 / img_size[0]
center_y = (y1 + y2) * 0.5 / img_size[1]
w = abs((x2 - x1)) * 1.0 / img_size[0]
h = abs((y2 - y1)) * 1.0 / img_size[1]
return (center_x, center_y, w, h)
def decode_json(jsonfloder_path<