First time here? Check out the FAQ!

Ask Your Question
3

Skipping frames in VideoCapture

asked Nov 28 '13

mrzl gravatar image

updated Jan 1 '16

I'm doing some motion detection on a video and while doing the processing, it sometimes is handy to simply skip a couple of frames in order to have a bigger impact on the e.g. optical flow detection. Currently I'm simply loading frames in a loop like that:

for( int i = 0; i < playbackSpeed; i++ )
{
    originalImage = videoReader.getNextImage();
}

Though I'd much rather just skip a couple of frames instead of just loading more, because doing this ends up in a little performance problem. Cheers for the help.

mrzl

Preview: (hide)

Comments

What is your hardware and os? What implementation of cv::VideoCapture do you use?

I'm using Win8 64bit with the standard cv::VideoCapture implementation ( not sure what you mean ) with opencv version 2.4.7

mrzl gravatar imagemrzl (Dec 13 '13)edit

2 answers

Sort by » oldest newest most voted
7

answered Nov 29 '13

Will Stewart gravatar image

updated Jan 23 '14

Assuming you are using VideoCapture in HighGUI, you can do n number of frame grabs, without actually loading the images;

http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-grab

"The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success."

This way you can quickly bypass however many frames you want. I do that in a loop with a parameter that I can pass in, in order to make adjustments during execution.

Preview: (hide)
0

answered Oct 3 '18

raghuk gravatar image

Again, assuming you are using VideoCapture in HighGUI, you can do set the CAP_PROP_POS_FRAMES property before grabbing/reading the frames. That way the next frame to be read will be from that frame onwards.

https://docs.opencv.org/2.4/modules/h...

Using this method you can set the CV_CAP_PROP_POS_FRAMES property to the frame number you want to quickly bypass however many frames you want. For example, in python 3 you would do it as:

import cv2
cap = cv2.VideoCapture('path/to/video/file')
start_frame_number = 50
cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame_number)

# Now when you read the frame, you will be reading the 50th frame
success, frame = cap.read()
Preview: (hide)

Question Tools

Stats

Asked: Nov 28 '13

Seen: 56,992 times

Last updated: Jan 23 '14