-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_Market_database.py
78 lines (72 loc) · 2.27 KB
/
create_Market_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
import argparse
import os
import pandas as pd
from collections import OrderedDict
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
]
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 = []
seq_ids = []
frame_ids = []
track_ids = []
for i, f in enumerate(files):
imgs.append(os.path.abspath(os.path.join(data_dir, f)))
v = f.split('_')
labels.append(int(v[0]))
cams.append(int(v[1][1]))
seq_ids.append(int(v[1][3]))
frame_ids.append(int(v[2]))
if i == 0 :
track_id = 0
else:
if prev_label == int(v[0]):
if prev_camseq == v[1]:
if (int(v[2]) - 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 = int(v[2])
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), ('seq_id',seq_ids),
('frame_id',frame_ids), ('track_id',track_ids)])
df = pd.DataFrame(d)
df.to_csv(args.output_txt, sep=' ', index=False)