1 | initial version |
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
2 | No.2 Revision |
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 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