-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_video.py
36 lines (27 loc) · 994 Bytes
/
process_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
import numpy as np
import cv2
video_name = 'color.avi'
cap = cv2.VideoCapture(video_name)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
npy_filename = 'npy_files/segment_info.npy'
segment_list = np.load(npy_filename)
frame_count = 0
segment_count = 0
while(cap.isOpened()):
ret, frame = cap.read()
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# cv2.imshow('frame',gray)
if ret and frame_count > 30 and frame_count < 2260 and frame_count < segment_list[segment_count]:
cv2.putText(frame, 'Action ' + str(segment_count) + ' ' + str(frame_count), (50, 50), cv2.FONT_ITALIC, 0.8, 255)
frame_count += 1
if frame_count >= segment_list[segment_count] and segment_count < segment_list.shape[0]:
segment_count += 1
out.write(frame)
cv2.imshow('frame', frame)
cv2.waitKey(5)
if cv2.waitKey(5) and 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()