-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract_frames.py
More file actions
25 lines (22 loc) · 941 Bytes
/
Copy pathextract_frames.py
File metadata and controls
25 lines (22 loc) · 941 Bytes
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
import os
import cv2
def extract_and_save_video_frames(videos_dir, frames_dir):
for emotion in os.listdir(videos_dir):
for video in os.listdir(os.path.join(videos_dir, emotion)):
video_name, _ = os.path.splitext(video)
horse_number = int(str(video_name).split("-")[0][1:])
horse_path = os.path.join(frames_dir, 'S' + str(horse_number))
emotion_path = os.path.join(horse_path, emotion)
vid = os.path.join(videos_dir, emotion, f'{video_name}.mp4')
cap = cv2.VideoCapture(vid)
i = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
img_name = os.path.join(emotion_path, f'{video_name}__{i}.jpg')
print(img_name)
cv2.imwrite(img_name, frame)
i += 1
cap.release()
cv2.destroyAllWindows()