7
7
8
8
namespace op
9
9
{
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)
11
12
{
12
13
try
13
14
{
@@ -17,21 +18,25 @@ namespace op
17
18
// However, we update every frame during the first few frames to have an initial estimator.
18
19
// In any of the previous cases, the fps value is estimated during the last several frames.
19
20
// 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)
23
22
{
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
+ }
35
40
}
36
41
}
37
42
catch (const std::exception& e)
@@ -46,7 +51,8 @@ namespace op
46
51
mNumberGpus {numberGpus},
47
52
mGuiEnabled {guiEnabled},
48
53
mFpsCounter {0u },
49
- mLastElementRenderedCounter {std::numeric_limits<int >::max ()}
54
+ mLastElementRenderedCounter {std::numeric_limits<int >::max ()},
55
+ mLastId {-1u }
50
56
{
51
57
}
52
58
@@ -57,10 +63,12 @@ namespace op
57
63
// Security checks
58
64
if (cvOutputData.empty ())
59
65
error (" Wrong input element (empty cvOutputData)." , __LINE__, __FUNCTION__, __FILE__);
60
- // Used colors
61
- const cv::Scalar white{255 ,255 ,255 };
66
+
62
67
// 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 };
64
72
// Fps or s/gpu
65
73
char charArrayAux[15 ];
66
74
std::snprintf (charArrayAux, 15 , " %4.1f fps" , mFps );
0 commit comments