diff options
author | Stéphane Lenclud <github@lenclud.com> | 2019-02-03 12:28:12 +0100 |
---|---|---|
committer | Stéphane Lenclud <github@lenclud.com> | 2019-02-07 13:24:13 +0100 |
commit | 1da2d0e71a03296a40b49316b5e23986de823a75 (patch) | |
tree | 287a1a1c3d7d5d31870b3a32fba69d72c9b7be1d /tracker-kinect-face/kinect_face_tracker.h | |
parent | 70156963a8f65d21231de88460e6559bd78f770c (diff) |
Kinect: Renaming a few files.
Diffstat (limited to 'tracker-kinect-face/kinect_face_tracker.h')
-rw-r--r-- | tracker-kinect-face/kinect_face_tracker.h | 113 |
1 files changed, 113 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..220a126f --- /dev/null +++ b/tracker-kinect-face/kinect_face_tracker.h @@ -0,0 +1,113 @@ + + + +#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: + Timer t; + + // Kinect stuff + static const int cColorWidth = 1920; + static const int cColorHeight = 1080; + + + void Update(); + HRESULT InitializeDefaultSensor(); + void ProcessFaces(); + HRESULT UpdateBodyData(IBody** ppBodies); + void ExtractFaceRotationInDegrees(const Vector4* pQuaternion, float* pPitch, float* pYaw, float* pRoll); + + // Current Kinect + IKinectSensor* m_pKinectSensor; + + // Coordinate mapper + ICoordinateMapper* m_pCoordinateMapper; + + // Color reader + IColorFrameReader* m_pColorFrameReader; + + // Body reader + IBodyFrameReader* m_pBodyFrameReader; + + // Face sources + IHighDefinitionFaceFrameSource* m_pFaceFrameSource; + + // Face readers + IHighDefinitionFaceFrameReader* m_pFaceFrameReader; + + // + RGBQUAD* m_pColorRGBX; + + RectI iFaceBox = { 0 }; + + CameraSpacePoint iLastFacePosition; + CameraSpacePoint iFacePosition; + CameraSpacePoint iFacePositionCenter; + + Vector4 iFaceRotationQuaternion; + // As Yaw, Pitch, Roll + CameraSpacePoint iLastFaceRotation; + CameraSpacePoint iFaceRotation; + CameraSpacePoint iFaceRotationCenter; + // + std::unique_ptr<cv_video_widget> iVideoWidget; + std::unique_ptr<QLayout> iLayout; +}; |