-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_DukeReID_database.py
82 lines (74 loc) · 2.4 KB
/
create_DukeReID_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import argparse
import os
import pandas as pd
from collections import OrderedDict
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
]
cam_offset = [5543, 3607, 27244, 31182, 1, 22402, 18968, 46766]
cam_offset = {i+1:49700-n for i,n in enumerate(cam_offset)}
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('data_dir')
parser.add_argument('output_txt')
parser.add_argument('--track_interval', type=int,
help='max interval between two detections to be considered as the same track for AFL')
args = parser.parse_args()
# Read images
data_dir = args.data_dir
files = sorted(os.listdir(data_dir))
files = [f for f in files if is_image_file(f)]
imgs = []
labels = []
cams = []
frame_ids = []
track_ids = []
for i, f in enumerate(files):
imgs.append(os.path.abspath(os.path.join(data_dir, f)))
v = f.split('.')[0].split('_')
labels.append(int(v[0]))
cam = int(v[1][1])
frame_id = int(v[2][1:])
cams.append(cam)
frame_ids.append(frame_id-cam_offset[cam])
if i == 0 :
track_id = 0
else:
if prev_label == int(v[0]):
if prev_camseq == v[1]:
if (frame_id - prev_frame) < args.track_interval:
track_id = prev_track_id
else:
track_id += 1
else:
track_id += 1
else:
track_id = 0
track_ids.append(track_id)
prev_camseq = v[1]
prev_label = int(v[0])
prev_frame = frame_id
prev_track_id = track_id
'''
# Re-index id:
# If id <=0: use original id
# If id >0: remap to start from 1
id_dict = {}
idx = 1
for id in labels:
if id not in id_dict:
if id <= 0:
id_dict[id] = id
else:
id_dict[id] = idx
idx += 1
labels = [id_dict[l] for l in labels]
'''
# Write file
d = OrderedDict([('img',imgs), ('label',labels), ('cam',cams),
('frame_id',frame_ids), ('track_id',track_ids)])
df = pd.DataFrame(d)
df.to_csv(args.output_txt, sep=' ', index=False)