-
Notifications
You must be signed in to change notification settings - Fork 3
/
record_video.py
49 lines (38 loc) · 1.5 KB
/
record_video.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
import cv2
import numpy as np
import cPickle
import argparse
parser = argparse.ArgumentParser(description="Run commands")
parser.add_argument('fname', type=str, help="Filename with frames and actions.")
parser.add_argument('-o', '--output', type=str, default='output.avi',
help="Output filename.")
parser.add_argument('-f', '--fps', type=int, default=10,
help="Frames per second.")
parser.add_argument('-c', '--codec', type=str, default='XVID',
help="Codec for video.")
args = parser.parse_args()
with open(args.fname, 'rb') as f:
run = cPickle.load(f)
frames = run['frames']
actions = run['actions']
action_meanings = run['action_meanings']
(h, w) = frames[0].shape[:2]
# create img for text
text_img = np.zeros((h/8, w, 3), dtype='uint8')
font = cv2.FONT_HERSHEY_SIMPLEX
thikness = 1
font_size = 0.4
# Define the codec and create VideoWriter object
fourcc = cv2.cv.FOURCC(*args.codec)
out = cv2.VideoWriter(args.output, fourcc, args.fps, (w, h + h/8))
for i, (frame, action) in enumerate(zip(frames, actions)):
# prepare text part
text_img.fill(255)
cv2.putText(text_img, 'action {}'.format(action_meanings[action]),
(2, text_img.shape[0] / 2 - 2), font, font_size, (0, 0, 0), thikness)
cv2.putText(text_img, 'frame {}'.format(i),
(2, text_img.shape[0] - 2), font, font_size, (0, 0, 0), thikness)
frame = np.vstack((frame, text_img))
out.write(frame)
# Release everything if job is finished
out.release()