OpenCV/Python: read specific frame using VideoCapture

The following code can accomplish that:

import cv2
cap = cv2.VideoCapture(videopath)
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number-1)
res, frame = cap.read()

frame_number is an integer in the range 0 to the number of frames in the video.
Notice: you should set frame_number-1 to force reading frame frame_number. It’s not documented well but that is how the VideoCapture module behaves.

One may obtain amount of frames by:

amount_of_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)