Merge pull request #26212 from jamacias:feature/TickMeter-lasttime

Enhance cv::TickMeter to be able to get the last elapsed time
pull/23867/merge
Alexander Smorkalov 1 month ago committed by GitHub
commit 1909ac8650
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 37
      modules/core/include/opencv2/core/utility.hpp
  2. 1
      samples/cpp/tutorial_code/snippets/core_various.cpp

@ -340,11 +340,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;
} }
@ -367,11 +368,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
{ {
@ -404,15 +429,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…
Cancel
Save