-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgen_json.py
51 lines (46 loc) · 1.62 KB
/
gen_json.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
from __future__ import unicode_literals
import json
from os.path import join, exists
import os
import pandas as pd
dataset_path = './data'
def parse_and_sched(dl_dir='.'):
# For each of the two datasets
f = open('./train_id.txt', 'r')
videos = f.readlines()
f.close()
n_videos = len(videos)
js = {}
for idx,video in enumerate(videos):
print('{}/{}'.format(idx,n_videos))
video = video.strip()
class_name = video.split('-')[0]
class_path = join(dataset_path, class_name)
gt_path = join(class_path, video, 'groundtruth.txt')
f = open(gt_path, 'r')
groundtruth = f.readlines()
f.close()
for idx, gt_line in enumerate(groundtruth):
gt_image = gt_line.strip().split(',')
frame = '%06d' % (int(idx))
obj = '%02d' % (int(0))
bbox = [int(float(gt_image[0])), int(float(gt_image[1])),
int(float(gt_image[0])) + int(float(gt_image[2])),
int(float(gt_image[1])) + int(float(gt_image[3]))] # xmin,ymin,xmax,ymax
x1 = bbox[0]
y1 = bbox[1]
w = bbox[2]
h = bbox[3]
if x1 < 0 or y1 < 0 or w <= 0 or h <= 0:
continue
if video not in js:
js[video] = {}
if obj not in js[video]:
js[video][obj] = {}
js[video][obj][frame] = bbox
json.dump(js, open('train.json', 'w'), indent=4, sort_keys=True)
js = {}
json.dump(js, open('val.json', 'w'), indent=4, sort_keys=True)
print('done')
if __name__ == '__main__':
parse_and_sched()