-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvideo_preprocessing.py
30 lines (25 loc) · 949 Bytes
/
video_preprocessing.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
import cv2
import os
def video_to_frames(video_path, out_path):
cap = cv2.VideoCapture(video_path)
if (cap.isOpened() == False):
print("Error opening video stream or file")
frame_count = 0
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
frame_count += 1
cv2.imwrite(out_path + "/frame" + str(frame_count) + ".jpg" , frame)
else:
break
cap.release()
def multi_videos_to_frame(videos_dir, out_path):
for video in os.listdir(videos_dir):
video_path = os.path.join(videos_dir, video)
out_video_path = os.path.join(out_path, video)
if not os.path.isdir(out_video_path):
os.mkdir(out_video_path)
if os.path.isfile(video_path):
video_to_frames(video_path, out_video_path)
if __name__ == '__main__':
multi_videos_to_frame("data/Avenue/training_videos", "data/Avenue/training_frames")