forked from Videmo/pymot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporters.py
114 lines (87 loc) · 2.97 KB
/
importers.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
from collections import deque
def MOT_hypo_import(lines):
frames = []
for line in lines:
# print line
s = deque(line.strip().split()) # any whitespace
# Skip empty lines
if len(s) < 1:
continue
ts = float(s.popleft())
# each hypothesis takes exactly 5 values
assert((len(s)) % 5 == 0)
nHypotheses = len(s) / 5
hypotheses = []
for i in range(nHypotheses):
hypo = {
'id': s[5*i + 0],
'x': float(s[5*i + 1]),
'y': float(s[5*i + 2]),
'width': float(s[5*i + 3]) - float(s[5*i + 1]), # x - tl_x
'height': float(s[5*i + 4]) - float(s[5*i + 2]), # y - tl_y
}
hypotheses.append(hypo)
frameitem = {
# no num
'class': 'frame',
'timestamp': ts,
'hypotheses': hypotheses,
}
frames.append(frameitem)
fileitem = {
'class': 'video',
'frames': frames,
}
return fileitem
def MOT_groundtruth_import(lines): # TODO rename, since we do not create json
frames = []
for line in lines:
s = deque(line.strip().split()) # any whitespace
# Skip empty lines
if len(s) < 1:
continue
ts = float(s.popleft())
# each annotation takes exactly 13 values
assert((len(s)) % 13 == 0)
nAnnotations = len(s) / 13
annotations = []
for i in range(nAnnotations):
id = s[13*i + 0]
cx = float(s[13*i + 3])
cy = float(s[13*i + 4])
w = float(s[13*i + 5])
h = float(s[13*i + 6])
# Ignore annotations with negative center coordinates
if cx < 0 and cy < 0:
continue
# Ground truth is considered a DCO object, if more than two features found
# Silly, but thats how the perl script seems to do it
nFeaturesGreaterThanZero = 0
for j in range(7, 13):
if float(s[13*i + j]) >= 0.0:
nFeaturesGreaterThanZero += 1
dco = True
if nFeaturesGreaterThanZero >= 2:
dco = False
annotation = {
'id': id,
'x': cx - w/2,
'y': cy - h/2,
'width': w,
'height': h,
'dco': dco,
}
annotations.append(annotation)
frameitem = {
# no num
'class': 'frame',
'timestamp': ts,
'annotations': annotations
}
frames.append(frameitem)
fileitem = {
'class': 'video',
'frames': frames,
}
return fileitem