From 1f82111bbee522c4d31372f9f64b903a08ccc11e Mon Sep 17 00:00:00 2001 From: Stéphane Lenclud Date: Sun, 3 Feb 2019 15:20:36 +0100 Subject: Kinect: Don't do video preview when not needed. --- tracker-kinect-face/kinect_face_tracker.cpp | 76 ++++++++++++++++------------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'tracker-kinect-face') diff --git a/tracker-kinect-face/kinect_face_tracker.cpp b/tracker-kinect-face/kinect_face_tracker.cpp index ab568f1e..5663de0f 100644 --- a/tracker-kinect-face/kinect_face_tracker.cpp +++ b/tracker-kinect-face/kinect_face_tracker.cpp @@ -5,6 +5,7 @@ #include #include +#include "compat/check-visible.hpp" /// @@ -308,6 +309,8 @@ HRESULT KinectFaceTracker::InitializeDefaultSensor() return hr; } + + /// /// Main processing function /// @@ -353,50 +356,57 @@ void KinectFaceTracker::Update() hr = pColorFrame->get_RawColorImageFormat(&imageFormat); } - if (SUCCEEDED(hr)) - { - // Fetch color buffer - if (imageFormat == ColorImageFormat_Rgba) - { - hr = pColorFrame->AccessRawUnderlyingBuffer(&nBufferSize, reinterpret_cast(&pBuffer)); - } - else if (m_pColorRGBX) - { - pBuffer = m_pColorRGBX; - nBufferSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); - hr = pColorFrame->CopyConvertedFrameDataToArray(nBufferSize, reinterpret_cast(pBuffer), ColorImageFormat_Rgba); - } - else - { - hr = E_FAIL; - } - - } - if (SUCCEEDED(hr)) { //DrawStreams(nTime, pBuffer, nWidth, nHeight); ProcessFaces(); } - if (SUCCEEDED(hr)) - { - // Setup our image - QImage image((const unsigned char*)pBuffer, cColorWidth, cColorHeight, sizeof(RGBQUAD)*cColorWidth, QImage::Format_RGBA8888); - if (IsValidRect(iFaceBox)) + if (check_is_visible()) + { + //OutputDebugStringA("Widget visible!\n"); + // If our widget is visible we feed it our frame + if (SUCCEEDED(hr)) { - // Draw our face bounding box - QPainter painter(&image); - painter.setBrush(Qt::NoBrush); - painter.setPen(QPen(Qt::red, 8)); - painter.drawRect(iFaceBox.Left, iFaceBox.Top, iFaceBox.Right - iFaceBox.Left, iFaceBox.Bottom - iFaceBox.Top); - bool bEnd = painter.end(); + // Fetch color buffer + if (imageFormat == ColorImageFormat_Rgba) + { + hr = pColorFrame->AccessRawUnderlyingBuffer(&nBufferSize, reinterpret_cast(&pBuffer)); + } + else if (m_pColorRGBX) + { + pBuffer = m_pColorRGBX; + nBufferSize = cColorWidth * cColorHeight * sizeof(RGBQUAD); + hr = pColorFrame->CopyConvertedFrameDataToArray(nBufferSize, reinterpret_cast(pBuffer), ColorImageFormat_Rgba); + } + else + { + hr = E_FAIL; + } + + } + + if (SUCCEEDED(hr)) + { + // Setup our image + QImage image((const unsigned char*)pBuffer, cColorWidth, cColorHeight, sizeof(RGBQUAD)*cColorWidth, QImage::Format_RGBA8888); + if (IsValidRect(iFaceBox)) + { + // Draw our face bounding box + QPainter painter(&image); + painter.setBrush(Qt::NoBrush); + painter.setPen(QPen(Qt::red, 8)); + painter.drawRect(iFaceBox.Left, iFaceBox.Top, iFaceBox.Right - iFaceBox.Left, iFaceBox.Bottom - iFaceBox.Top); + bool bEnd = painter.end(); + } + + // Update our video preview + iVideoWidget->update_image(image); } - // Update our video preview - iVideoWidget->update_image(image); } + SafeRelease(pFrameDescription); } -- cgit v1.2.3