-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconverter.py
More file actions
33 lines (31 loc) · 1.37 KB
/
converter.py
File metadata and controls
33 lines (31 loc) · 1.37 KB
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
import scipy.io as sio
import os
import json
ORIGIN_PATH = 'benchmark_py/results/OPE'
EXPORT_PATH = 'benchmark_mat/results/OPE'
trackers = os.listdir(ORIGIN_PATH)
for tracker in trackers:
files = os.listdir(os.path.join(ORIGIN_PATH, tracker))
for filename in files:
if filename[-4:] == 'json':
fHandle = open(os.path.join(ORIGIN_PATH, tracker, filename))
tmpfile = json.load(fHandle)
fHandle.close()
seqLen = len(tmpfile)
extracted = []
for i in range(seqLen):
tmp_old = tmpfile[i]
tmp_new = {}
if 'tmplsize' in tmp_old.keys() and tmp_old['tmplsize'] is not None:
tmp_new['tmplsize'] = tmp_old['tmplsize']
tmp_new['type'] = tmp_old['resType']
tmp_new['len'] = tmp_old['endFrame'] - tmp_old['startFrame'] + 1
if tracker != 'NCC':
tmp_new['res'] = tmp_old['res']
else:
tmp_new['res'] = []
for rect in tmp_old['res']:
tmp_new['res'].append([float(rect[0]), float(rect[1]), float(rect[2]), float(rect[3])])
extracted.append(tmp_new)
matFileName = filename[:-5].lower() + '_' + tracker
sio.savemat(os.path.join(EXPORT_PATH, matFileName), {'results':extracted})