Ask Your Question

Can we set on every fifth video frame to be processed instead of having all the frames per second to be processed?

asked 2014-10-06 08:23:16 -0500

zms gravatar image

Hello, Does anyone know how to process selected frames in the video? for example the video fps = 30 but I want to process every 5th of the frames eg. 0,5,10,15,20,25,30 to reduce the processing time. I have checked the videocapture class but not able to select it.

Appreciate if anyone can give me the idea on this.


edit retag flag offensive close merge delete



solve FIZZBUZZ , and you know how ..

berak gravatar imageberak ( 2014-10-06 09:42:31 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-10-06 09:59:41 -0500

Increment a framecounter every frame and then put your process block inside this condition.

if (framecounter % 5 == 0)

This condition will verify when framecounter is a multiple of 5, which will happen every 5 frames.

edit flag offensive delete link more


Thanks for the answer.. it worked as per recommended.. this is the snippet

int index = cap.get(CV_CAP_PROP_POS_FRAMES);

if (index % 10 == 0) { processing block }

P/S: Is there any other recommendation on how to process the video faster other by sampling the video frame?


zms gravatar imagezms ( 2014-10-07 01:22:01 -0500 )edit

Every piece of processing code may be subject to optimization. Even opencv's algorithms are constantly being optimized. You'll have to verify if your code is will written for speed. Please accept the answer if it solved your problem :)

Pedro Batista gravatar imagePedro Batista ( 2014-10-07 05:02:05 -0500 )edit

Ok I accept the answer.. Thanks!!! :)

zms gravatar imagezms ( 2014-10-07 08:04:21 -0500 )edit

I normally write it as if (framecounter++ % 5 == 0) so that I don't have to think of the increment later.

FooBar gravatar imageFooBar ( 2014-10-07 09:59:29 -0500 )edit

Emm, actually I had tried to create the framecounter function but I don't think I had succeed with that due to my lack of knowledge in programming. A bit slow for a newbie like me..

zms gravatar imagezms ( 2014-10-07 11:07:40 -0500 )edit

Question Tools


Asked: 2014-10-06 08:23:16 -0500

Seen: 3,213 times

Last updated: Oct 06 '14