Ask Your Question
3

Skipping frames in VideoCapture

asked 2013-11-28 14:49:36 -0600

mrzl gravatar image

updated 2016-01-01 14:30:30 -0600

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

edit retag flag offensive close merge delete

Comments

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

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-11-29 00:56:29 -0600 )edit

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 ( 2013-12-13 09:55:52 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
7

answered 2013-11-28 18:40:58 -0600

Will Stewart gravatar image

updated 2014-01-23 05:32:38 -0600

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.

edit flag offensive delete link more
0

answered 2018-10-03 06:43:23 -0600

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()
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-28 14:49:36 -0600

Seen: 55,207 times

Last updated: Jan 23 '14