summaryrefslogtreecommitdiffhomepage
path: root/tracker-easy/tracker-easy.cpp
diff options
context:
space:
mode:
authorStéphane Lenclud <github@lenclud.com>2019-04-16 12:23:22 +0200
committerStéphane Lenclud <github@lenclud.com>2019-04-24 18:46:12 +0200
commit1fb6122dce1a5bc117e925006d87828a52cfecb6 (patch)
tree0c6250bc59b93cdc92a4df75ab77d0e88690e8b2 /tracker-easy/tracker-easy.cpp
parent5e2f6182f41d7c027f58b110bc8c6e539a50ac2c (diff)
Easy Tracker: Cheap way to dramatically improve CPU usage. Now displaying FPS info on frame preview.
Diffstat (limited to 'tracker-easy/tracker-easy.cpp')
-rw-r--r--tracker-easy/tracker-easy.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp
index 8bae883a..68e3be36 100644
--- a/tracker-easy/tracker-easy.cpp
+++ b/tracker-easy/tracker-easy.cpp
@@ -27,8 +27,10 @@ using namespace options;
// Disable debug
#define dbgout if (true) {} else std::cout
+//#define infout if (true) {} else std::cout
// Enable debug
//#define dbgout if (false) {} else std::cout
+#define infout if (false) {} else std::cout
namespace EasyTracker
{
@@ -125,10 +127,13 @@ namespace EasyTracker
{
maybe_reopen_camera();
+ iFpsTimer.start();
+
while (!isInterruptionRequested())
{
- bool new_frame = false;
+ iTimer.start();
+ bool new_frame = false;
{
QMutexLocker l(&camera_mtx);
@@ -144,7 +149,7 @@ namespace EasyTracker
// Create OpenCV matrix from our frame
// TODO: Assert channel size is one or two
iMatFrame = cv::Mat(iFrame.height, iFrame.width, CV_MAKETYPE((iFrame.channelSize == 2 ? CV_16U : CV_8U), iFrame.channels), iFrame.data, iFrame.stride);
-
+ iFrameCount++;
const bool preview_visible = check_is_visible();
if (preview_visible)
@@ -268,7 +273,11 @@ namespace EasyTracker
}
if (preview_visible)
- {
+ {
+ std::ostringstream ss;
+ ss << "FPS: " << iFps << "/" << iSkippedFps;
+ iPreview.DrawInfo(ss.str());
+
//
if (topPointIndex != -1)
{
@@ -302,6 +311,27 @@ namespace EasyTracker
cv::destroyWindow("Preview");
}
}
+
+ dbgout << "Frame time:" << iTimer.elapsed_seconds() << "\n";
+ }
+ else
+ {
+ iSkippedFrameCount++;
+ }
+
+ // Pace ourselves, drastically reduce CPU usage
+ // TODO: Consider using QTimer instead of QThread
+ msleep(1000 / 55);
+
+ // Compute FPS
+ double elapsed = iFpsTimer.elapsed_seconds();
+ if (elapsed >= 1.0)
+ {
+ iFps = iFrameCount / elapsed;
+ iSkippedFps = iSkippedFrameCount / elapsed;
+ iFrameCount = 0;
+ iSkippedFrameCount = 0;
+ iFpsTimer.start();
}
}
}