-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.py
More file actions
75 lines (58 loc) · 2.15 KB
/
utilities.py
File metadata and controls
75 lines (58 loc) · 2.15 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
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
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.patches import Rectangle
from skimage.io import imread
from skimage import filters, img_as_float
import os
def load_frames(imgs_dir):
frames = [img_as_float(imread(os.path.join(imgs_dir, frame),
as_grey=True)) \
for frame in sorted(os.listdir(imgs_dir))]
return frames
def load_bboxes(gt_path):
bboxes = []
with open(gt_path) as f:
for line in f:
x, y, w, h = line.split(',')
bboxes.append((int(x), int(y), int(w), int(h)))
return bboxes
def animated_frames(frames, figsize=(10,8)):
fig, ax = plt.subplots(figsize=figsize)
ax.axis('off')
im = ax.imshow(frames[0])
def animate(i):
im.set_array(frames[i])
return [im,]
ani = animation.FuncAnimation(fig, animate, frames=len(frames),
interval=60, blit=True)
return ani
def animated_scatter(frames, trajs, figsize=(10,8)):
fig, ax = plt.subplots(figsize=figsize)
ax.axis('off')
im = ax.imshow(frames[0])
scat = ax.scatter(trajs[0][:,1], trajs[0][:,0],
facecolors='none', edgecolors='r')
def animate(i):
im.set_array(frames[i])
if len(trajs[i]) > 0:
scat.set_offsets(trajs[i][:,[1,0]])
else: # If no trajs to draw
scat.set_offsets([]) # clear the scatter plot
return [im, scat,]
ani = animation.FuncAnimation(fig, animate, frames=len(frames),
interval=60, blit=True)
return ani
def animated_bbox(frames, bboxes, figsize=(10,8)):
fig, ax = plt.subplots(figsize=figsize)
ax.axis('off')
im = ax.imshow(frames[0])
x, y, w, h = bboxes[0]
bbox = ax.add_patch(Rectangle((x,y),w,h, linewidth=3,
edgecolor='r', facecolor='none'))
def animate(i):
im.set_array(frames[i])
bbox.set_bounds(*bboxes[i])
return [im, bbox,]
ani = animation.FuncAnimation(fig, animate, frames=len(frames),
interval=60, blit=True)
return ani