Skip to content

Commit fd35bd9

Browse files
GUI info adder working multi-frame
1 parent b47c780 commit fd35bd9

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

include/openpose/gui/guiInfoAdder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace op
2626
unsigned int mFpsCounter;
2727
std::string mLastElementRenderedName;
2828
int mLastElementRenderedCounter;
29+
unsigned long long mLastId;
2930
};
3031
}
3132

src/openpose/gui/guiInfoAdder.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace 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

Comments
 (0)