diff options
Diffstat (limited to 'tracker-kinect-face')
-rw-r--r-- | tracker-kinect-face/camera_kinect_ir.cpp | 332 | ||||
-rw-r--r-- | tracker-kinect-face/camera_kinect_ir.h | 6 |
2 files changed, 168 insertions, 170 deletions
diff --git a/tracker-kinect-face/camera_kinect_ir.cpp b/tracker-kinect-face/camera_kinect_ir.cpp index e170b15a..b881d51f 100644 --- a/tracker-kinect-face/camera_kinect_ir.cpp +++ b/tracker-kinect-face/camera_kinect_ir.cpp @@ -10,7 +10,7 @@ #ifdef OTR_HAVE_OPENCV -//#include "frame.hpp" + //#include "frame.hpp" #include "compat/sleep.hpp" #include "compat/math-imports.hpp" @@ -28,7 +28,7 @@ namespace Kinect { { if (name.compare(KKinectIRSensor) == 0) { - return std::make_unique<CameraKinectIr>(); + return std::make_unique<InfraredCamera>(); } return nullptr; @@ -49,239 +49,237 @@ namespace Kinect { return false; } -// Register our camera provider thus making sure Point Tracker can use Kinect V2 IR Sensor -OTR_REGISTER_CAMERA(CamerasProvider) + // Register our camera provider thus making sure Point Tracker can use Kinect V2 IR Sensor + OTR_REGISTER_CAMERA(CamerasProvider) -CameraKinectIr::CameraKinectIr() -{ -} - + InfraredCamera::InfraredCamera() + { + } -CameraKinectIr::~CameraKinectIr() -{ - stop(); -} -bool CameraKinectIr::show_dialog() -{ - return false; -} + InfraredCamera::~InfraredCamera() + { + stop(); + } -bool CameraKinectIr::is_open() -{ - return iInfraredFrameReader!=nullptr; -} + bool InfraredCamera::show_dialog() + { + return false; + } -/// -/// Wait until we get a first frame -/// -void CameraKinectIr::WaitForFirstFrame() -{ - bool new_frame = false; - int attempts = 200; // Kinect cold start can take a while - while (!new_frame && attempts>0) + bool InfraredCamera::is_open() { - new_frame = get_frame_(iMatFrame); - portable::sleep(100); - --attempts; + return iInfraredFrameReader != nullptr; } -} + /// + /// Wait until we get a first frame + /// + void InfraredCamera::WaitForFirstFrame() + { + bool new_frame = false; + int attempts = 200; // Kinect cold start can take a while + while (!new_frame && attempts > 0) + { + new_frame = get_frame_(iMatFrame); + portable::sleep(100); + --attempts; + } + } -std::tuple<const video::impl::frame&, bool> CameraKinectIr::get_frame() -{ - bool new_frame = false; - new_frame = get_frame_(iMatFrame); - - iFrame.data = iMatFrame.ptr(); - iFrame.width = iWidth; - iFrame.height = iHeight; - iFrame.stride = cv::Mat::AUTO_STEP; - iFrame.channels = iMatFrame.channels(); - iFrame.channelSize = iMatFrame.elemSize1(); - return { iFrame, new_frame }; -} -// Safe release for interfaces -template<class Interface> -inline void SafeRelease(Interface *& pInterfaceToRelease) -{ - if (pInterfaceToRelease != NULL) + std::tuple<const video::impl::frame&, bool> InfraredCamera::get_frame() { - pInterfaceToRelease->Release(); - pInterfaceToRelease = NULL; - } -} - -/// -/// -/// -bool CameraKinectIr::start(info& aInfo) -{ - stop(); + bool new_frame = false; + new_frame = get_frame_(iMatFrame); - HRESULT hr; + iFrame.data = iMatFrame.ptr(); + iFrame.width = iWidth; + iFrame.height = iHeight; + iFrame.stride = cv::Mat::AUTO_STEP; + iFrame.channels = iMatFrame.channels(); + iFrame.channelSize = iMatFrame.elemSize1(); + return { iFrame, new_frame }; + } - // Get and open Kinect sensor - hr = GetDefaultKinectSensor(&iKinectSensor); - if (SUCCEEDED(hr)) + // Safe release for interfaces + template<class Interface> + inline void SafeRelease(Interface *& pInterfaceToRelease) { - hr = iKinectSensor->Open(); + if (pInterfaceToRelease != NULL) + { + pInterfaceToRelease->Release(); + pInterfaceToRelease = NULL; + } } - // Create infrared frame reader - if (SUCCEEDED(hr)) + /// + /// + /// + bool InfraredCamera::start(info& aInfo) { - // Initialize the Kinect and get the infrared reader - IInfraredFrameSource* pInfraredFrameSource = NULL; + stop(); - hr = iKinectSensor->Open(); + HRESULT hr; + // Get and open Kinect sensor + hr = GetDefaultKinectSensor(&iKinectSensor); if (SUCCEEDED(hr)) { - hr = iKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource); + hr = iKinectSensor->Open(); } + // Create infrared frame reader if (SUCCEEDED(hr)) { - hr = pInfraredFrameSource->OpenReader(&iInfraredFrameReader); - } + // Initialize the Kinect and get the infrared reader + IInfraredFrameSource* pInfraredFrameSource = NULL; - SafeRelease(pInfraredFrameSource); + hr = iKinectSensor->Open(); - if (SUCCEEDED(hr)) - { - iKinectSensor->get_CoordinateMapper(&iCoordinateMapper); - } - } + if (SUCCEEDED(hr)) + { + hr = iKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource); + } + if (SUCCEEDED(hr)) + { + hr = pInfraredFrameSource->OpenReader(&iInfraredFrameReader); + } - if (SUCCEEDED(hr)) - { - WaitForFirstFrame(); - bool success = iMatFrame.ptr() != nullptr; - if (success) - { - // Provide frame info - aInfo.width = iWidth; - aInfo.height = iHeight; + SafeRelease(pInfraredFrameSource); - CameraIntrinsics intrinsics; - hr = iCoordinateMapper->GetDepthCameraIntrinsics(&intrinsics); if (SUCCEEDED(hr)) { - aInfo.focalLengthX = intrinsics.FocalLengthX; - aInfo.focalLengthY = intrinsics.FocalLengthY; - aInfo.principalPointX = intrinsics.PrincipalPointX; - aInfo.principalPointY = intrinsics.PrincipalPointY; - aInfo.radialDistortionFourthOrder = intrinsics.RadialDistortionFourthOrder; - aInfo.radialDistortionSecondOrder = intrinsics.RadialDistortionSecondOrder; - aInfo.radialDistortionSixthOrder = intrinsics.RadialDistortionSixthOrder; + iKinectSensor->get_CoordinateMapper(&iCoordinateMapper); } - } - return success; - } - stop(); - return false; -} + if (SUCCEEDED(hr)) + { + WaitForFirstFrame(); + bool success = iMatFrame.ptr() != nullptr; + if (success) + { + // Provide frame info + aInfo.width = iWidth; + aInfo.height = iHeight; + + CameraIntrinsics intrinsics; + hr = iCoordinateMapper->GetDepthCameraIntrinsics(&intrinsics); + if (SUCCEEDED(hr)) + { + aInfo.focalLengthX = intrinsics.FocalLengthX; + aInfo.focalLengthY = intrinsics.FocalLengthY; + aInfo.principalPointX = intrinsics.PrincipalPointX; + aInfo.principalPointY = intrinsics.PrincipalPointY; + aInfo.radialDistortionFourthOrder = intrinsics.RadialDistortionFourthOrder; + aInfo.radialDistortionSecondOrder = intrinsics.RadialDistortionSecondOrder; + aInfo.radialDistortionSixthOrder = intrinsics.RadialDistortionSixthOrder; + } -void CameraKinectIr::stop() -{ - // done with infrared frame reader - SafeRelease(iInfraredFrame); - SafeRelease(iInfraredFrameReader); + } - // close the Kinect Sensor - if (iKinectSensor) - { - iKinectSensor->Close(); + return success; + } + + stop(); + return false; } - SafeRelease(iCoordinateMapper); - SafeRelease(iKinectSensor); + void InfraredCamera::stop() + { + // done with infrared frame reader + SafeRelease(iInfraredFrame); + SafeRelease(iInfraredFrameReader); - // Free up our memory buffer if any - iMatFrame = cv::Mat(); -} + // close the Kinect Sensor + if (iKinectSensor) + { + iKinectSensor->Close(); + } -bool CameraKinectIr::get_frame_(cv::Mat& aFrame) -{ + SafeRelease(iCoordinateMapper); + SafeRelease(iKinectSensor); - if (!iInfraredFrameReader) - { - return false; + // Free up our memory buffer if any + iMatFrame = cv::Mat(); } - bool success = false; + bool InfraredCamera::get_frame_(cv::Mat& aFrame) + { - // Release previous frame if any - SafeRelease(iInfraredFrame); + if (!iInfraredFrameReader) + { + return false; + } - HRESULT hr = iInfraredFrameReader->AcquireLatestFrame(&iInfraredFrame); + bool success = false; - if (SUCCEEDED(hr)) - { - if (iFirstFrame) - { - IFrameDescription* frameDescription = NULL; + // Release previous frame if any + SafeRelease(iInfraredFrame); - if (SUCCEEDED(hr)) - { - hr = iInfraredFrame->get_FrameDescription(&frameDescription); - } + HRESULT hr = iInfraredFrameReader->AcquireLatestFrame(&iInfraredFrame); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr)) + { + if (iFirstFrame) { - hr = frameDescription->get_Width(&iWidth); + IFrameDescription* frameDescription = NULL; + + if (SUCCEEDED(hr)) + { + hr = iInfraredFrame->get_FrameDescription(&frameDescription); + } + + if (SUCCEEDED(hr)) + { + hr = frameDescription->get_Width(&iWidth); + } + + if (SUCCEEDED(hr)) + { + hr = frameDescription->get_Height(&iHeight); + } + + if (SUCCEEDED(hr)) + { + hr = frameDescription->get_DiagonalFieldOfView(&iFov); + } + + if (SUCCEEDED(hr)) + { + iFirstFrame = false; + } + + SafeRelease(frameDescription); } - if (SUCCEEDED(hr)) - { - hr = frameDescription->get_Height(&iHeight); - } + + UINT nBufferSize = 0; + UINT16 *pBuffer = NULL; if (SUCCEEDED(hr)) { - hr = frameDescription->get_DiagonalFieldOfView(&iFov); + hr = iInfraredFrame->AccessUnderlyingBuffer(&nBufferSize, &pBuffer); } if (SUCCEEDED(hr)) { - iFirstFrame = false; + // Create an OpenCV matrix with our 16-bits IR buffer + aFrame = cv::Mat(iHeight, iWidth, CV_16UC1, pBuffer, cv::Mat::AUTO_STEP); + // Any processing of the frame is left to the user + success = true; } - - SafeRelease(frameDescription); } - UINT nBufferSize = 0; - UINT16 *pBuffer = NULL; - - if (SUCCEEDED(hr)) - { - hr = iInfraredFrame->AccessUnderlyingBuffer(&nBufferSize, &pBuffer); - } - - if (SUCCEEDED(hr)) - { - // Create an OpenCV matrix with our 16-bits IR buffer - aFrame = cv::Mat(iHeight, iWidth, CV_16UC1, pBuffer, cv::Mat::AUTO_STEP); - // Any processing of the frame is left to the user - success = true; - } + return success; } - - return success; -} - - - } #endif diff --git a/tracker-kinect-face/camera_kinect_ir.h b/tracker-kinect-face/camera_kinect_ir.h index b88efdcd..83acb4d6 100644 --- a/tracker-kinect-face/camera_kinect_ir.h +++ b/tracker-kinect-face/camera_kinect_ir.h @@ -39,10 +39,10 @@ namespace Kinect { /// /// Implement our camera interface using Kinect V2 SDK IR Sensor. /// -struct CameraKinectIr final : video::impl::camera +struct InfraredCamera final : video::impl::camera { - CameraKinectIr(); - ~CameraKinectIr() override; + InfraredCamera(); + ~InfraredCamera() override; // From video::impl::camera [[nodiscard]] bool start(info& args) override; |