import os
import json
import cv2
for file in os.listdir('/media/lixuan/workSpace/浙江中烟130106/已知场景'):
if 'bvv4nhptub0lfvhip6jg.json' in file:
img = cv2.imread('/media/lixuan/workSpace/test/images/train/{}.jpg'.format(file.split('.')[0]))
fw = open('/media/lixuan/workSpace/浙江中烟130106/txt/{}.txt'.format(file.split('.')[0]),'w')
with open('/media/lixuan/workSpace/浙江中烟130106/已知场景/{}'.format(file)) as f:
dic = json.load(f)
shapes = dic['shapes']
imageHeight = dic['imageHeight']
imageWidth = dic['imageWidth']
for shape in shapes:
label = shape['label']
points = shape['points']
x1 = points[0][0]
y1 = points[0][1]
x2 = points[1][0]
y2 = points[1][1]
x = (x1 + x2) / 2 / imageWidth
y = (y1 + y2) / 2 / imageHeight
w = (x2 - x1) / imageWidth
h = (y2 - y1) / imageHeight
fw.write(label + ' ' + str(x) + ' ' + str(y) + ' ' + str(w) + ' ' + str(h) + '\n')
fw.close()
labelme解析为yolov5
最新推荐文章于 2024-08-05 08:30:00 发布