-
Notifications
You must be signed in to change notification settings - Fork 127
/
draw_bbox.py
127 lines (106 loc) · 3.69 KB
/
draw_bbox.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
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
from config import *
from scripts import *
def main():
evalTypes = ['OPE', 'SRE', 'TRE']
print "Eval types"
for i in range(len(evalTypes)):
evalType = evalTypes[i]
print "{0:2d}. {1}".format(i+1, evalType)
while True:
n = int(raw_input("\nInput evalType number (-1 to exit) : "))
if n == -1:
sys.exit()
try:
evalType = evalTypes[n-1]
break
except:
print "invalid number"
src = RESULT_SRC.format(evalType)
trackers = os.listdir(src)
print "\nTrackers"
for i in range(len(trackers)):
t = trackers[i]
print "{0:2d}. {1}".format(i+1, t)
while True:
n = int(raw_input("\nInput tracker number (-1 to exit) : "))
if n == -1:
sys.exit()
try:
tracker = trackers[n-1]
break
except:
print "invalid number"
src = os.path.join(src, tracker)
seqs = [x for x in os.listdir(src) if x.endswith('.json')]
while True:
print "\nSequences"
for i in range(len(seqs)):
s = seqs[i]
print "{0:2d}. {1}".format(i+1, s)
results = []
n = int(raw_input("\nInput sequence number (-1 to exit) : "))
if n == -1:
sys.exit()
try:
resultFile = open(os.path.join(src, seqs[n-1]))
except:
print "invalid number"
string = resultFile.read()
jsonList = json.loads(string)
for j in jsonList:
result = Result(**j)
results.append(result)
for i in range(len(results)):
result = results[i]
print "{0:2d}. startFrame : {1},\tshiftType : {2}".format(i+1, result.startFrame, result.shiftType)
n = int(raw_input("\nInput result number (-1 to exit) : "))
if n == -1:
sys.exit()
try:
result = results[n-1]
except:
print "invalid number"
continue
seq = butil.load_seq_config(result.seqName)
startFrame = result.startFrame
view_result(seq, result.res, startFrame)
def view_result(seq, res, startIndex):
fig = plt.figure()
src = os.path.join(SEQ_SRC, seq.name)
image = Image.open(src + '/img/{0:04d}.jpg'.format(startIndex)).convert('RGB')
im = plt.imshow(image, zorder=0)
x, y, w, h = get_coordinate(res[0])
gx, gy, gw, gh = get_coordinate(seq.gtRect[startIndex-seq.startFrame])
rect = plt.Rectangle((x, y), w, h,
linewidth=5, edgecolor="#ff0000", zorder=1, fill=False)
gtRect = plt.Rectangle((gx, gy), gw, gh,
linewidth=5, edgecolor="#00ff00", zorder=1, fill=False)
plt.gca().add_patch(rect)
plt.gca().add_patch(gtRect)
def update_fig(num, startIndex, res, gt, src, startFrame):
r = res[num]
g = gt[num+startIndex-startFrame]
x, y, w, h = get_coordinate(r)
gx, gy, gw, gh = get_coordinate(g)
i = startIndex + num
image = Image.open(src + '/img/{0:04d}.jpg'.format(i)).convert('RGB')
im.set_data(image)
rect.set_xy((x,y))
rect.set_width(w)
rect.set_height(h)
gtRect.set_xy((gx,gy))
gtRect.set_width(gw)
gtRect.set_height(gh)
return im, rect, gtRect
ani = animation.FuncAnimation(fig, update_fig,
frames=len(res), fargs=(startIndex, res, seq.gtRect, src, seq.startFrame), interval=10, blit=True)
plt.axis("off")
plt.show()
def get_coordinate(res):
return int(res[0]), int(res[1]), int(res[2]), int(res[3])
if __name__ == '__main__':
main()