50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import os
|
|
|
|
|
|
label_path_1 = '/home/admin-root/haotian/python哈汽锻8安全帽识别/头鞋数据集/head_imgs/labels_head'
|
|
label_path_2 = '/home/admin-root/haotian/python哈汽锻8安全帽识别/头鞋数据集/head_imgs/labels_shoe'
|
|
|
|
label_output_path = '/home/admin-root/haotian/python哈汽锻8安全帽识别/头鞋数据集/head_imgs/labels'
|
|
|
|
label_names = os.listdir(label_path_1)
|
|
|
|
for label_name in label_names:
|
|
|
|
# 原始标签路径, lp1 head: 1, lp2 shoe:2
|
|
lp1 = os.path.join(label_path_1, label_name)
|
|
lp2 = os.path.join(label_path_2, label_name)
|
|
|
|
# 新的标签路径
|
|
lop = os.path.join(label_output_path, label_name)
|
|
|
|
labels = list()
|
|
|
|
with open(lp1, 'r') as f:
|
|
lines1 = f.readlines()
|
|
|
|
for line in lines1:
|
|
try:
|
|
class_id, x_center, y_center, box_width, box_height = map(float, line.split())
|
|
labels.append(f"1 {x_center} {y_center} {box_width} {box_height}\n")
|
|
except:
|
|
|
|
print("lp1 解析标签文件出错")
|
|
|
|
with open(lp2, 'r') as f:
|
|
lines2 = f.readlines()
|
|
|
|
for line in lines2:
|
|
try:
|
|
class_id, x_center, y_center, box_width, box_height = map(float, line.split())
|
|
labels.append(f"2 {x_center} {y_center} {box_width} {box_height}\n")
|
|
except:
|
|
|
|
print("lp2 解析标签文件出错")
|
|
|
|
with open(lop, 'w') as f:
|
|
f.writelines(labels)
|
|
|
|
|
|
|
|
|