Ask Your Question
-1

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 -0600

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.

Zamani

edit retag flag offensive close merge delete

Comments

1

solve FIZZBUZZ , and you know how ..

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

1 answer

Sort by ยป oldest newest most voted
3

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

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

if (framecounter % 5 == 0)
{
  //processing...
}

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

edit flag offensive delete link more

Comments

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?

Zamani

zms gravatar imagezms ( 2014-10-07 01:22:01 -0600 )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 -0600 )edit

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

zms gravatar imagezms ( 2014-10-07 08:04:21 -0600 )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 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 4,959 times

Last updated: Oct 06 '14