-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (31 loc) · 1.07 KB
/
utils.py
File metadata and controls
43 lines (31 loc) · 1.07 KB
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
import cv2
def split_frames(video_path, output_path):
"""
split frames of video and put into output_path folder
"""
frame_id = 0
# Open the video file
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Error opening video file")
return
while cap.isOpened():
# Read the video file frame by frame
ret, frame = cap.read()
# If 'ret' is True then 'frame' contains a valid image
if ret:
# You can use the 'frame' for further processing like face recognition, object detection etc.
# Save frame as image
cv2.imwrite(f'{output_path}/frame_{frame_id}.png', frame)
frame_id += 1
# Press Q on keyboard to exit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# Break the loop if no more frames are available
else:
print('no more frames!')
break
# Release the video capture object and close windows
cap.release()
cv2.destroyAllWindows()
return frame_id