From b3b43a5216afbcaf5ed15fe73a5e156672cf6488 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jan 2020 22:52:27 +0100 Subject: tracker/kinect: sleep when identical frame received --- tracker-kinect-face/camera_kinect_ir.cpp | 18 +++++++++++++++++- tracker-kinect-face/camera_kinect_ir.h | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tracker-kinect-face/camera_kinect_ir.cpp b/tracker-kinect-face/camera_kinect_ir.cpp index 81357a6d..024fd703 100644 --- a/tracker-kinect-face/camera_kinect_ir.cpp +++ b/tracker-kinect-face/camera_kinect_ir.cpp @@ -221,6 +221,7 @@ namespace Kinect { bool InfraredCamera::get_frame_(cv::Mat& aFrame) { + unsigned attempts = 0; if (!iInfraredFrameReader) { @@ -231,11 +232,26 @@ namespace Kinect { // Release previous frame if any SafeRelease(iInfraredFrame); - +start: HRESULT hr = iInfraredFrameReader->AcquireLatestFrame(&iInfraredFrame); if (SUCCEEDED(hr)) { + + { + TIMESPAN t = 0; + + (void)iInfraredFrame->get_RelativeTime(&t); + + if (t == timestamp && ++attempts < 10) + { + portable::sleep(2); + goto start; + } + + timestamp = t; + } + if (iFirstFrame) { IFrameDescription* frameDescription = NULL; diff --git a/tracker-kinect-face/camera_kinect_ir.h b/tracker-kinect-face/camera_kinect_ir.h index 83acb4d6..5dfb43bc 100644 --- a/tracker-kinect-face/camera_kinect_ir.h +++ b/tracker-kinect-face/camera_kinect_ir.h @@ -16,7 +16,7 @@ #include "compat/timer.hpp" #include "video/camera.hpp" - +#include #include #include @@ -67,6 +67,7 @@ private: // ICoordinateMapper* iCoordinateMapper = nullptr; + std::int64_t timestamp = 0; video::frame iFrame; cv::Mat iMatFrame; -- cgit v1.2.3