-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframe.py
More file actions
35 lines (26 loc) · 1020 Bytes
/
Copy pathframe.py
File metadata and controls
35 lines (26 loc) · 1020 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
26
27
28
29
30
31
32
33
34
import cv2
def extract_frame(video_path, output_image_path, frame_number):
# Open the video file
cap = cv2.VideoCapture(video_path)
# Check if the video opened successfully
if not cap.isOpened():
print("Error: Could not open video.")
return
# Set the frame position
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
# Read the specified frame
ret, frame = cap.read()
if ret:
# Save the frame as a JPG file
cv2.imwrite(output_image_path, frame)
print(f"Frame {frame_number} saved as {output_image_path}")
else:
print(f"Error: Could not read frame {frame_number}.")
# Release the video capture object
cap.release()
# Define input and output paths
video_path = 'output/final/output_video101.mp4'
output_image_path = 'data/output_frame2.jpg'
frame_number = 103 # Change this to select a different frame
# Extract and save the specified frame
extract_frame(video_path, output_image_path, frame_number)