mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Enhance cv::TickMeter to be able to get the last ellapsed time
This commit is contained in:
parent
450e741f8d
commit
679931dcde
@ -309,11 +309,12 @@ public:
|
|||||||
//! stops counting ticks.
|
//! stops counting ticks.
|
||||||
CV_WRAP void stop()
|
CV_WRAP void stop()
|
||||||
{
|
{
|
||||||
int64 time = cv::getTickCount();
|
const int64 time = cv::getTickCount();
|
||||||
if (startTime == 0)
|
if (startTime == 0)
|
||||||
return;
|
return;
|
||||||
++counter;
|
++counter;
|
||||||
sumTime += (time - startTime);
|
lastTime = time - startTime;
|
||||||
|
sumTime += lastTime;
|
||||||
startTime = 0;
|
startTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,11 +337,35 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! returns passed time in seconds.
|
//! returns passed time in seconds.
|
||||||
CV_WRAP double getTimeSec() const
|
CV_WRAP double getTimeSec() const
|
||||||
{
|
{
|
||||||
return (double)getTimeTicks() / getTickFrequency();
|
return (double)getTimeTicks() / getTickFrequency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! returns counted ticks of the last iteration.
|
||||||
|
CV_WRAP int64 getLastTimeTicks() const
|
||||||
|
{
|
||||||
|
return lastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! returns passed time of the last iteration in microseconds.
|
||||||
|
CV_WRAP double getLastTimeMicro() const
|
||||||
|
{
|
||||||
|
return getLastTimeMilli()*1e3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! returns passed time of the last iteration in milliseconds.
|
||||||
|
CV_WRAP double getLastTimeMilli() const
|
||||||
|
{
|
||||||
|
return getLastTimeSec()*1e3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! returns passed time of the last iteration in seconds.
|
||||||
|
CV_WRAP double getLastTimeSec() const
|
||||||
|
{
|
||||||
|
return (double)getLastTimeTicks() / getTickFrequency();
|
||||||
|
}
|
||||||
|
|
||||||
//! returns internal counter value.
|
//! returns internal counter value.
|
||||||
CV_WRAP int64 getCounter() const
|
CV_WRAP int64 getCounter() const
|
||||||
{
|
{
|
||||||
@ -373,15 +398,17 @@ public:
|
|||||||
//! resets internal values.
|
//! resets internal values.
|
||||||
CV_WRAP void reset()
|
CV_WRAP void reset()
|
||||||
{
|
{
|
||||||
startTime = 0;
|
|
||||||
sumTime = 0;
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
sumTime = 0;
|
||||||
|
startTime = 0;
|
||||||
|
lastTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64 counter;
|
int64 counter;
|
||||||
int64 sumTime;
|
int64 sumTime;
|
||||||
int64 startTime;
|
int64 startTime;
|
||||||
|
int64 lastTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief output operator
|
/** @brief output operator
|
||||||
|
@ -78,6 +78,7 @@ int main()
|
|||||||
tm.start();
|
tm.start();
|
||||||
// do something ...
|
// do something ...
|
||||||
tm.stop();
|
tm.stop();
|
||||||
|
cout << "Last iteration: " << tm.getLastTimeSec() << endl;
|
||||||
}
|
}
|
||||||
cout << "Average time per iteration in seconds: " << tm.getAvgTimeSec() << endl;
|
cout << "Average time per iteration in seconds: " << tm.getAvgTimeSec() << endl;
|
||||||
cout << "Average FPS: " << tm.getFPS() << endl;
|
cout << "Average FPS: " << tm.getFPS() << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user