Skip to content

Instantly share code, notes, and snippets.

@vereperrot
Created December 19, 2019 08:55
Show Gist options
  • Save vereperrot/dd2263e220e68555d687f2ed2075d590 to your computer and use it in GitHub Desktop.
Save vereperrot/dd2263e220e68555d687f2ed2075d590 to your computer and use it in GitHub Desktop.
read specific frame using VideoCapture
# https://stackoverflow.com/questions/33650974/opencv-python-read-specific-frame-using-videocapture
import numpy as np
import cv2
cap = cv2.VideoCapture(video_name) #video_name is the video being called
cap.set(1,frame_no); # Where frame_no is the frame you want
ret, frame = cap.read() # Read the frame
cv2.imshow('window_name', frame) # show frame on window
#If you want to hold the window, until you press exit:
while True:
ch = 0xFF & cv2.waitKey(1) # Wait for a second
if ch == 27:
break
@TonyTheTaiga
Copy link

Needed this, thanks

@Dvarkian
Copy link

Dvarkian commented Sep 2, 2023

Thanks for uploading this! It was exactly what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment