-
Notifications
You must be signed in to change notification settings - Fork 5
/
visualize.py
94 lines (86 loc) · 3.05 KB
/
visualize.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
import numpy as np
import cv2
import matplotlib.pyplot as plt
from sfm import decompose_affine
def plot_motion(motion, sm_motion=None):
"""motion is an Nx3x3 homograph matrix for N frames describing the motion between each
successive frame as:
[ ]"""
for ii in range(motion.shape[1]):
for jj in range(motion.shape[2]):
plt.plot(motion[:,ii, jj], label='M[{},{}]'.format(ii+1, jj+1))
if sm_motion is not None:
plt.gca().set_prop_cycle(None)
for ii in range(motion.shape[1]):
for jj in range(motion.shape[2]):
plt.plot(sm_motion[:,ii, jj], linestyle="--", label='M[{},{}] (stab)'.format(ii+1, jj+1))
plt.title('motion trajectories')
plt.legend()
plt.xlabel('frame #')
plt.show()
def plot_motion_affine(motion, sm_motion=None ):
"""motion is an Nx3x3 homograph matrix for N frames describing the motion between each
successive frame as:
[ ]"""
(S, R, T) = decompose_affine(motion, vectors=True)
plt.subplot(2,1,1)
plt.title('motion trajectories')
plt.plot(S[:,0], label='Sx')
plt.plot(S[:,1], label='Sy')
plt.plot(R, label='R')
plt.subplot(2,1,2)
plt.gca().set_prop_cycle(None)
plt.plot(T[:,0], label='Tx')
plt.plot(T[:,1], label='Ty')
if sm_motion is not None:
(S, R, T) = decompose_affine(sm_motion, vectors=True)
plt.subplot(2,1,1)
plt.gca().set_prop_cycle(None)
plt.plot(S[:,0], linestyle='--', label='Sx (stab)')
plt.plot(S[:,1], linestyle='--', label='Sy (stab)')
plt.plot(R, linestyle='--', label='R (stab)')
plt.legend()
plt.subplot(2,1,2)
plt.gca().set_prop_cycle(None)
plt.plot(T[:,0], linestyle='--', label='Tx (stab)')
plt.plot(T[:,1], linestyle='--', label='Ty (stab)')
plt.legend()
plt.legend()
plt.xlabel('frame #')
plt.show()
def interactive_play_video(varr, framerate=None, features=None):
if not framerate:
framerate = 24
playing = True
dotsize = int(varr.shape[0]//100*2.5)
ii = 0
while ii<varr.shape[0]:
frame = varr[ii].copy()
if features is not None:
pts = features[ii]
for pt in pts:
# for pt in pts[np.random.choice(len(pts), min(20,len(pts)), replace=False)]:
pt = np.squeeze(pt)
if len(pt)==2:
cv2.circle(frame, (pt[0], pt[1]), dotsize, (0,0,255), -1)
cv2.imshow('features', frame)
while True:
keyp = cv2.waitKey(int(1/framerate*1000))
if keyp==ord(' ') or keyp==83: #right
break
elif keyp==81: # left
ii-=2
break
elif keyp==ord('p'):
playing = not playing
break
elif keyp==ord('q') :
cv2.destroyWindow('features')
return
elif playing:
break
if ii == varr.shape[0]-1:
ii = 0
continue
ii += 1
cv2.destroyAllWindows()