行人搜索中有ID 标签(第二列),但是目标检测中没有ID,因此要把第二列去掉
import glob
import os
import cv2
import csv
import math
import random
import shutil
from PIL import Image
labelpath = "E:\\workspace\\dataset\\PRW\\labels_with_ids"
labelpath_new = "E:\\workspace\\dataset\\PRW\\labels_wo_ids"
if __name__ == "__main__":
labels_file_names = glob.glob(os.path.join(labelpath, '*.txt'))
file_name_new = ""
for file_name in labels_file_names:
for line in open(file_name, "r"): # 设置文件对象
words = line.split(' ')
file_name = file_name.replace('\\', '/')
file_name_wo_dir = file_name.split("/")[-1]
if os.path.join(labelpath_new, file_name_wo_dir) != file_name_new:
file_name_new =os.path.join(labelpath_new, file_name_wo_dir)
fw = open(file_name_new, 'w')
else:
fw = open(file_name_new, 'a')
str1 = str(words[0]) + " " + str(words[2]) + " " + str(words[3]) + " " + str(words[4]) + " " + str(words[5])
fw.write(str1)
fw.close()