-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt-to-mat.py
36 lines (32 loc) · 1.04 KB
/
txt-to-mat.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
import os
import scipy.io as scio
import numpy as np
file = '/**/model/' #your txt path
savefile = '/**/result/' # your mat file path
pathlist = os.listdir(file)
# print(pathlist)
for i in range(len(pathlist)):
path = os.path.join(file, pathlist[i])
for j in range(len(pathlist[i])):
if pathlist[i][j] == '.':
save = pathlist[i][:j]
break
savepath = savefile + save + '_SiamRPN++.mat' ## your tracker name (here we use SiamRPN++)
f = open(path)
data = f.readlines()
result = []
for j in range(len(data)):
x = data[j].split(',')
x[3] = float(x[3][:-1])
x[0] = float(x[0])
x[1] = float(x[1])
x[2] = float(x[2])
result.append(x)
res = {}
res['res'] = result
res['type'] = 'rect'
Mat = {'res': res['res'], 'type': 'rect', 'len': len(res['res']), 'annoBegin': 1, 'startFrame': 1}
M = np.array([Mat])
Mat2 = {'__header__': 'b', '__version__': 1.0, '__globals__': [], 'results': M}
scio.savemat(savepath, Mat2)
# print(data)