-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_on_video
47 lines (37 loc) · 1.1 KB
/
graph_on_video
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
import cv2
import matplotlib.pyplot as plt
import numpy as np
filename = './bunny.mp4'
cap = cv2.VideoCapture(filename)
try:
frames = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
width = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
except AttributeError:
frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fig, ax = plt.subplots(1,1)
plt.ion()
plt.show()
#Setup a dummy path
x = np.linspace(0,width,frames)
y = x/2. + 100*np.sin(2.*np.pi*x/1200)
# def on_key(event):
# global keep_ploting
# keep_ploting = False
for i in range(frames):
fig.clf()
flag, frame = cap.read()
plt.imshow(frame)
plt.plot(x,y,'k-', lw=2)
plt.plot(x[i],y[i],'or')
plt.pause(0.001)
# fig.canvas.mpl_connect('key_press_event', on_key)
# if cv2.waitKey(1) == 27:
# if cv2.waitKey(10) & 0xFF == ord('q'):
# cap.release()
# cv2.destroyAllWindows()
# break
# cap.release()
# cv2.destroyAllWindows()