vott标注文件csv转yolov5脚本
import os
import csv
CLASS_MAPPING = {
'ziji': 0,
'npc': 1,
'gebulin': 2,
'rennanyao': 3,
'rennvyao': 4,
'rensiqi': 5
}
MAX_X = 1544
MAX_Y = 720
csv_file_path = 'data/video/biaozhu/vott-csv-export/teon-export.csv'
output_dir = 'data/video/biaozhu/2/'
with open(csv_file_path, newline='') as f:
reader = csv.reader(f)
next(reader, None)
for row in reader:
filepath, xmin, ymin, xmax, ymax, class_name = row
label_num = CLASS_MAPPING[class_name]
x_center = ((float(xmax) + float(xmin)) / 2) / MAX_X
y_center = ((float(ymax) + float(ymin)) / 2) / MAX_Y
width = (float(xmax) - float(xmin)) / MAX_X
height = (float(ymax) - float(ymin)) / MAX_Y
label_file = os.path.join(output_dir, os.path.splitext(os.path.basename(filepath))[0] + '.txt')
with open(label_file, mode='a') as f2:
f2.write('{} {:.6f} {:.6f} {:.6f} {:.6f}\n'.format(label_num, x_center, y_center, width, height))
print('转换完成')