-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_extract.py
30 lines (24 loc) · 908 Bytes
/
image_extract.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
"""
Extracting random frame as sample for resizing, to account for
not being able to transmit a numpy array over MQTT. To reference
a reshape size, this script is used to extract a frame from the
video file and save it as an image.
"""
frame_num = 50 # extract 50th frame as sample (arbitrary)
def save_frame(video_path, output_path):
cap = cv2.VideoCapture(video_path)
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
ret, frame = cap.read()
if ret:
# Save the frame as an image
cv2.imwrite(output_path, frame)
print(f"Random frame saved to {output_path}")
else:
print("Error: Unable to read frame from the video.")
# Release the video capture object
cap.release()
if __name__ == "__main__":
input_video_path = "data/camdata.avi"
output_image_path = "data/sample_frame.png"
save_frame(input_video_path, output_image_path)