77
88namespace op
99{
10- void getFps (double & fps, unsigned int & fpsCounter, std::queue<std::chrono::high_resolution_clock::time_point>& fpsQueue, const int numberGpus)
10+ void updateFps (unsigned long long & lastId, double & fps, unsigned int & fpsCounter, std::queue<std::chrono::high_resolution_clock::time_point>& fpsQueue,
11+ const unsigned long long id, const int numberGpus)
1112 {
1213 try
1314 {
@@ -17,21 +18,25 @@ namespace op
1718 // However, we update every frame during the first few frames to have an initial estimator.
1819 // In any of the previous cases, the fps value is estimated during the last several frames.
1920 // In this way, a sudden fps drop will be quickly visually identified.
20- fpsQueue.emplace (std::chrono::high_resolution_clock::now ());
21- bool updatePrintedFps = true ;
22- if (fpsQueue.size () > 5 )
21+ if (lastId != id)
2322 {
24- const auto factor = (numberGpus > 1 ? 25u : 15u );
25- updatePrintedFps = (fpsCounter % factor == 0 );
26- // updatePrintedFps = (numberGpus == 1 ? true : fpsCounter % (3*numberGpus) == 0);
27- fpsCounter++;
28- if (fpsQueue.size () > factor)
29- fpsQueue.pop ();
30- }
31- if (updatePrintedFps)
32- {
33- const auto timeSec = (double )std::chrono::duration_cast<std::chrono::nanoseconds>(fpsQueue.back ()-fpsQueue.front ()).count () * 1e-9 ;
34- fps = (fpsQueue.size ()-1 ) / (timeSec != 0 . ? timeSec : 1 .);
23+ lastId = id;
24+ fpsQueue.emplace (std::chrono::high_resolution_clock::now ());
25+ bool updatePrintedFps = true ;
26+ if (fpsQueue.size () > 5 )
27+ {
28+ const auto factor = (numberGpus > 1 ? 25u : 15u );
29+ updatePrintedFps = (fpsCounter % factor == 0 );
30+ // updatePrintedFps = (numberGpus == 1 ? true : fpsCounter % (3*numberGpus) == 0);
31+ fpsCounter++;
32+ if (fpsQueue.size () > factor)
33+ fpsQueue.pop ();
34+ }
35+ if (updatePrintedFps)
36+ {
37+ const auto timeSec = (double )std::chrono::duration_cast<std::chrono::nanoseconds>(fpsQueue.back ()-fpsQueue.front ()).count () * 1e-9 ;
38+ fps = (fpsQueue.size ()-1 ) / (timeSec != 0 . ? timeSec : 1 .);
39+ }
3540 }
3641 }
3742 catch (const std::exception& e)
@@ -46,7 +51,8 @@ namespace op
4651 mNumberGpus {numberGpus},
4752 mGuiEnabled {guiEnabled},
4853 mFpsCounter {0u },
49- mLastElementRenderedCounter {std::numeric_limits<int >::max ()}
54+ mLastElementRenderedCounter {std::numeric_limits<int >::max ()},
55+ mLastId {-1u }
5056 {
5157 }
5258
@@ -57,10 +63,12 @@ namespace op
5763 // Security checks
5864 if (cvOutputData.empty ())
5965 error (" Wrong input element (empty cvOutputData)." , __LINE__, __FUNCTION__, __FILE__);
60- // Used colors
61- const cv::Scalar white{255 ,255 ,255 };
66+
6267 // Update fps
63- getFps (mFps , mFpsCounter , mFpsQueue , mNumberGpus );
68+ updateFps (mLastId , mFps , mFpsCounter , mFpsQueue , id, mNumberGpus );
69+
70+ // Used colors
71+ const cv::Scalar white{255 , 255 , 255 };
6472 // Fps or s/gpu
6573 char charArrayAux[15 ];
6674 std::snprintf (charArrayAux, 15 , " %4.1f fps" , mFps );
0 commit comments