fairmot:darklabel制作的数据集格式转成MOT16 gt.txt 文件格式
import os
'''
gt.txt:
---------
frame(从1开始计), id(从1开始计), box(left top w, h),ignore=1(不忽略), class=1(从1开始),覆盖=1),
1,1,1363,569,103,241,1,1,0.86014
2,1,1362,568,103,241,1,1,0.86173
3,1,1362,568,103,241,1,1,0.86173
4,1,1362,568,103,241,1,1,0.86173
cutout24_gt.txt
---
frame(从0开始计), 数量, id(从0开始计), box(x1,y1,x2,y2), class=null
0,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null
1,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null
2,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null
'''
def xyxy2xywh(x):
# Convert bounding box format from [x1, y1, x2, y2] to [x, y, w, h]
# y = torch.zeros_like(x) if isinstance(x,
# torch.Tensor) else np.zeros_like(x)
y = [0, 0, 0, 0]
y[0] = (x[0] + x[2]) / 2
y[1] = (x[1] + x[3]) / 2
y[2] = x[2] - x[0]
y[3] = x[3] - x[1]
return y
def max_id(video_label_path):
human_id_ = list()
human_ID_list = list()
base=2
f=open(video_label_path, "r")
file_content = f.readlines()
for line in file_content:
line=line[:-1]
num_list = [num for num in line.split(',')]
curr_line_total_id=int(num_list[1])
for i in range(curr_line_total_id):
human_id_.append(int(num_list[base + i * 6]))
#print(human_id_)
for i in range(int(max(human_id_))+1):
human_ID_list.append(list())
f.close()
return human_ID_list
def ID_list_gen(video_label_path):
human_ID_list=max_id(video_label_path)
#print('the length of human_ID_list:{}'.format(len(human_ID_list)))
f = open(video_label_path, "r")
file_content=f.readlines()
base=2
for line in file_content:
line=line[:-1]
num_list=[num for num in line.split(',')]
total_num = int(num_list[1])
frame_ID=int(num_list[0])+1
curr_line_id=list()
for i in range(total_num):
curr_line_id.append(num_list[base+i*6])
#print('curr_line_id_count:{}'.format(curr_line_id))
for i,val in enumerate(curr_line_id):
_id = int(num_list[base + i * 6]) + 1
#print('_id :{}'.format(_id))
_box_x1 = int(num_list[base + i * 6 + 1])
_box_y1 = int(num_list[base + i * 6 + 2])
_box_x2 = int(num_list[base + i * 6 + 3])
_box_y2 = int(num_list[base + i * 6 + 4])
y = xyxy2xywh([_box_x1, _box_y1, _box_x2, _box_y2])
human_ID_list[int(val)].append([frame_ID, _id, int(y[0]), int(y[1]), int(y[2]), int(y[3]), 1, 1, 1])
f.close()
return human_ID_list
def iter_ID_list(root_dir,mot16_label_path):
human_id_list=ID_list_gen(root_dir)
f_o = open(mot16_label_path, "w")
for i in range(len(human_id_list)):
for j in range(len(human_id_list[i])):
#print(human_id_list[i][j])
write_line=','.join(map(str,human_id_list[i][j]))
print(write_line)
f_o.write(write_line+'\n')
f_o.close()
if __name__ == "__main__":
root_dir = '/home/.../fairmot/datasets/motcustomdataset/images/train'
for item in os.listdir(root_dir):
darklabel_gt_txt_dir = os.path.join(root_dir, item, 'gt', item + '_gt.txt')
mot16_fort_label_path = os.path.join(root_dir, item, 'gt', "gt.txt")
iter_ID_list(darklabel_gt_txt_dir,mot16_fort_label_path)