/* Copyright (c) 2019, Stephane Lenclud * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, * provided that the above copyright notice and this permission * notice appear in all copies. */ #pragma once #include #include "api/plugin-api.hpp" #include "compat/timer.hpp" #include "compat/macros.hpp" #include "video/video-widget.hpp" // Kinect Header files #include #include // @deprecated Use UniqueInterface instead. Remove it at some point. template inline void SafeRelease(Interface *& pInterfaceToRelease) { if (pInterfaceToRelease != nullptr) { pInterfaceToRelease->Release(); pInterfaceToRelease = nullptr; } } template inline void ReleaseInterface(Interface* pInterfaceToRelease) { if (pInterfaceToRelease != nullptr) { pInterfaceToRelease->Release(); } } // Safely use Microsoft interfaces. template class UniqueInterface : public std::unique_ptr)> ///**/ { public: UniqueInterface() : std::unique_ptr)>(nullptr, ReleaseInterface){} // Access pointer, typically for creation T** PtrPtr() { return &iPtr; }; // Called this once the pointer was created void Reset() { std::unique_ptr)>::reset(iPtr); } // If ever you want to release that interface before the object is deleted void Free() { iPtr = nullptr; Reset(); } private: T* iPtr = nullptr; }; // // // class KinectFaceTracker : public ITracker { public: KinectFaceTracker(); ~KinectFaceTracker() override; module_status start_tracker(QFrame* aFrame) override; void data(double *data) override; bool center() override; private: // Kinect stuff void Update(); HRESULT InitializeDefaultSensor(); void ProcessFaces(); HRESULT UpdateBodyData(IBody** ppBodies); void ExtractFaceRotationInDegrees(const Vector4* pQuaternion, float* pPitch, float* pYaw, float* pRoll); static IBody* FindClosestBody(IBody** aBodies); static IBody* FindTrackedBodyById(IBody** aBodies,UINT64 aTrackingId); // Timer iTimer; // Current Kinect IKinectSensor* iKinectSensor = nullptr; // Color reader IColorFrameReader* iColorFrameReader = nullptr; // Body reader IBodyFrameReader* iBodyFrameReader = nullptr; // Face sources IHighDefinitionFaceFrameSource* iFaceFrameSource = nullptr; // Face readers IHighDefinitionFaceFrameReader* iFaceFrameReader = nullptr; // RGBQUAD* iColorRGBX = nullptr; RectI iFaceBox = { 0 }; // Face position CameraSpacePoint iLastFacePosition = { 0 }; CameraSpacePoint iFacePosition = { 0 }; CameraSpacePoint iFacePositionCenter = { 0 }; Vector4 iFaceRotationQuaternion = { 0 }; // As Yaw, Pitch, Roll CameraSpacePoint iLastFaceRotation = { 0 }; CameraSpacePoint iFaceRotation = { 0 }; CameraSpacePoint iFaceRotationCenter = { 0 }; // std::unique_ptr iVideoWidget; std::unique_ptr iLayout; // Id of the body currently being tracked UINT64 iTrackingId = 0; };