Ask Your Question

how do you measure the time delay of two consecutive frames in a live videostream

asked 2015-08-14 15:05:37 -0600

Hi guys, I am trying to determine the delay of two consecutive video frames from a webcam/videocam. the idea is, when a certain object passes by my camera, I need to determine how long the object stays in the camera's field of vision. I detect the said object and the number of frames it has stayed inside cameras vision. What I want to do is measure the real-time delay between two consecutive frames. In doing so, i can add up the time delays based on the number of frames the object is present.

Please help. btw, feel free to suggest another method in obtaining time. that is my ultimate objective anyway

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-08-15 04:56:03 -0600

LBerger gravatar image

may be you can have a look here and try with parameter CV_CAP_PROP_POS_MSEC.

If it does not work you can use gettickcount

edit flag offensive delete link more


@LBerger I think the CV_CAP_PROP_POS_MSEC will not work since it is a live feed and not a video that he is processing. As for the .gettickcount it seems that it could be an option.

theodore gravatar imagetheodore ( 2015-08-15 05:27:48 -0600 )edit

answered 2015-08-15 05:17:57 -0600

theodore gravatar image

updated 2015-08-15 05:20:37 -0600

It used to exist the TickMeter class which for some reason I cannot find now somewhere in order to be able to include it in the source code (if someone knows what is the issue with it at the moment, I think that it would be nice to give us his lights). As you can see with this class there are the methods of .start() and .end(). So in your case what you could do, it would be to create an object of this class TickMeter timer; and when you would for the first time detect the object to start it timer.start(); detect/track the object through frames and when the object disappears stop it with timer.end(); and then you could just call one of the other methods, .getTimeMicro(), .getTimeMilli() or .getTimeSec() in order to obtain the time passed in microseconds, milliseconds or seconds respectively and I think that is what you need. TickMeter timer; // initialize timer timer.start(); // start timer when you first detect the object timer.end(); // end timer when the object disappears timer.getTimeSec(); // get time in seconds or whatever format you want

If for some reason we cannot use this function anymore you can include the #include <ctime> header instead and apply something similar like:

time_t timer_begin,timer_end;
time ( &timer_begin ); // start timer when you first detect the object
time ( &timer_end ); // end timer when the object disappears
double secondsElapsed = difftime ( timer_end,timer_begin ); // get time in seconds, if you want it in other format you will need to make the correspondent calculations

and another alternative is the std::clock() function again of the ctime header.

const clock_t begin_time = clock(); // start timer when you first detect the object
std::cout << float( clock () - begin_time ) /  CLOCKS_PER_SEC; // get time when the object disappears
begin_time = clock(); // you will need to re-initialize your timer though
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-08-14 15:05:37 -0600

Seen: 697 times

Last updated: Aug 15 '15