diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-02-09 06:27:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-09 06:27:23 +0100 |
commit | b41fdd0111baf86132c3b61b8e1e6085635e77be (patch) | |
tree | 2caea6565fe3c2b070ab5260380664246a4d10fb /tracker-kinect-face/kinect_face_tracker.h | |
parent | b9d34a26d35d05f793161e54001329edb5122a81 (diff) | |
parent | 26ad3d2b154f9161cf577060f9b161e3312b5e76 (diff) |
Merge pull request #869 from Slion/tracker-kinect-face
Tracker kinect face
Diffstat (limited to 'tracker-kinect-face/kinect_face_tracker.h')
-rw-r--r-- | tracker-kinect-face/kinect_face_tracker.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tracker-kinect-face/kinect_face_tracker.h b/tracker-kinect-face/kinect_face_tracker.h new file mode 100644 index 00000000..6273cba1 --- /dev/null +++ b/tracker-kinect-face/kinect_face_tracker.h @@ -0,0 +1,117 @@ + + + +#include <cmath> + +#include "api/plugin-api.hpp" +#include "compat/timer.hpp" +#include "compat/macros.hpp" +#include "cv/video-widget.hpp" + +// Kinect Header files +#include <Kinect.h> +#include <Kinect.Face.h> + +#pragma once + +// @deprecated Use UniqueInterface instead. Remove it at some point. +template<class Interface> +inline void SafeRelease(Interface *& pInterfaceToRelease) +{ + if (pInterfaceToRelease != nullptr) + { + pInterfaceToRelease->Release(); + pInterfaceToRelease = nullptr; + } +} + +template<class Interface> +inline void ReleaseInterface(Interface* pInterfaceToRelease) +{ + if (pInterfaceToRelease != nullptr) + { + pInterfaceToRelease->Release(); + } +} + +// Safely use Microsoft interfaces. +template<typename T> +class UniqueInterface : public std::unique_ptr<T, decltype(&ReleaseInterface<T>)> ///**/ +{ +public: + UniqueInterface() : std::unique_ptr<T, decltype(&ReleaseInterface<T>)>(nullptr, ReleaseInterface<T>){} + // Access pointer, typically for creation + T** PtrPtr() { return &iPtr; }; + // Called this once the pointer was created + void Reset() { std::unique_ptr<T, decltype(&ReleaseInterface<T>)>::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<cv_video_widget> iVideoWidget; + std::unique_ptr<QLayout> iLayout; + + // Id of the body currently being tracked + UINT64 iTrackingId = 0; +}; |