增加多屏显示,视频播放

This commit is contained in:
liuyunhui
2025-09-19 14:40:23 +08:00
parent fded7b9a51
commit 9076a5ea41
112 changed files with 24986 additions and 21 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,298 @@
/* this ALWAYS GENERATED file contains the definitions for the interfaces */
/* File created by MIDL compiler version 8.00.0595 */
/* at Sun Oct 19 12:54:09 2014
*/
/* Compiler settings for ..\..\idl\Kinect.INPC.idl:
Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.00.0595
protocol : dce , ms_ext, c_ext, robust
error checks: allocation ref bounds_check enum stub_data
VC __declspec() decoration level:
__declspec(uuid()), __declspec(selectany), __declspec(novtable)
DECLSPEC_UUID(), MIDL_INTERFACE()
*/
/* @@MIDL_FILE_HEADING( ) */
#pragma warning( disable: 4049 ) /* more than 64k source lines */
/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#endif
/* verify that the <rpcsal.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCSAL_H_VERSION__
#define __REQUIRED_RPCSAL_H_VERSION__ 100
#endif
#include "rpc.h"
#include "rpcndr.h"
#ifndef __RPCNDR_H_VERSION__
#error this stub requires an updated version of <rpcndr.h>
#endif // __RPCNDR_H_VERSION__
#ifndef COM_NO_WINDOWS_H
#include "windows.h"
#include "ole2.h"
#endif /*COM_NO_WINDOWS_H*/
#ifndef __Kinect2EINPC_h__
#define __Kinect2EINPC_h__
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
/* Forward Declarations */
#ifndef __INotifyPropertyChanged_FWD_DEFINED__
#define __INotifyPropertyChanged_FWD_DEFINED__
typedef interface INotifyPropertyChanged INotifyPropertyChanged;
#endif /* __INotifyPropertyChanged_FWD_DEFINED__ */
#ifndef __IPropertyChangedEventArgs_FWD_DEFINED__
#define __IPropertyChangedEventArgs_FWD_DEFINED__
typedef interface IPropertyChangedEventArgs IPropertyChangedEventArgs;
#endif /* __IPropertyChangedEventArgs_FWD_DEFINED__ */
/* header files for imported files */
#include "oaidl.h"
#include "ocidl.h"
#include "mmreg.h"
#ifdef __cplusplus
extern "C"{
#endif
/* interface __MIDL_itf_Kinect2EINPC_0000_0000 */
/* [local] */
typedef INT_PTR WAITABLE_HANDLE;
typedef INT64 TIMESPAN;
extern RPC_IF_HANDLE __MIDL_itf_Kinect2EINPC_0000_0000_v0_0_c_ifspec;
extern RPC_IF_HANDLE __MIDL_itf_Kinect2EINPC_0000_0000_v0_0_s_ifspec;
#ifndef __INotifyPropertyChanged_INTERFACE_DEFINED__
#define __INotifyPropertyChanged_INTERFACE_DEFINED__
/* interface INotifyPropertyChanged */
/* [object][local][uuid] */
EXTERN_C const IID IID_INotifyPropertyChanged;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("D27A5C77-32E9-4283-A046-9D693E29E3E7")
INotifyPropertyChanged : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE SubscribePropertyChanged(
/* [annotation][out][retval] */
_Out_ WAITABLE_HANDLE *waitableHandle) = 0;
virtual HRESULT STDMETHODCALLTYPE UnsubscribePropertyChanged(
/* [annotation][in] */
_In_ WAITABLE_HANDLE waitableHandle) = 0;
virtual HRESULT STDMETHODCALLTYPE GetPropertyChangedEventData(
/* [annotation][in] */
_In_ WAITABLE_HANDLE waitableHandle,
UINT bufferSize,
/* [annotation][out][retval] */
_Out_writes_z_(bufferSize) WCHAR *propertyName) = 0;
};
#else /* C style interface */
typedef struct INotifyPropertyChangedVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
INotifyPropertyChanged * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
INotifyPropertyChanged * This);
ULONG ( STDMETHODCALLTYPE *Release )(
INotifyPropertyChanged * This);
HRESULT ( STDMETHODCALLTYPE *SubscribePropertyChanged )(
INotifyPropertyChanged * This,
/* [annotation][out][retval] */
_Out_ WAITABLE_HANDLE *waitableHandle);
HRESULT ( STDMETHODCALLTYPE *UnsubscribePropertyChanged )(
INotifyPropertyChanged * This,
/* [annotation][in] */
_In_ WAITABLE_HANDLE waitableHandle);
HRESULT ( STDMETHODCALLTYPE *GetPropertyChangedEventData )(
INotifyPropertyChanged * This,
/* [annotation][in] */
_In_ WAITABLE_HANDLE waitableHandle,
UINT bufferSize,
/* [annotation][out][retval] */
_Out_writes_z_(bufferSize) WCHAR *propertyName);
END_INTERFACE
} INotifyPropertyChangedVtbl;
interface INotifyPropertyChanged
{
CONST_VTBL struct INotifyPropertyChangedVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define INotifyPropertyChanged_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define INotifyPropertyChanged_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define INotifyPropertyChanged_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define INotifyPropertyChanged_SubscribePropertyChanged(This,waitableHandle) \
( (This)->lpVtbl -> SubscribePropertyChanged(This,waitableHandle) )
#define INotifyPropertyChanged_UnsubscribePropertyChanged(This,waitableHandle) \
( (This)->lpVtbl -> UnsubscribePropertyChanged(This,waitableHandle) )
#define INotifyPropertyChanged_GetPropertyChangedEventData(This,waitableHandle,bufferSize,propertyName) \
( (This)->lpVtbl -> GetPropertyChangedEventData(This,waitableHandle,bufferSize,propertyName) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __INotifyPropertyChanged_INTERFACE_DEFINED__ */
#ifndef __IPropertyChangedEventArgs_INTERFACE_DEFINED__
#define __IPropertyChangedEventArgs_INTERFACE_DEFINED__
/* interface IPropertyChangedEventArgs */
/* [object][local][uuid] */
EXTERN_C const IID IID_IPropertyChangedEventArgs;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("574E9321-9DD9-41C8-BC51-C11F3F38D6B5")
IPropertyChangedEventArgs : public IUnknown
{
public:
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_PropertyName(
UINT bufferSize,
/* [annotation][out][retval] */
_Out_writes_z_(bufferSize) WCHAR *propertyName) = 0;
};
#else /* C style interface */
typedef struct IPropertyChangedEventArgsVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IPropertyChangedEventArgs * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IPropertyChangedEventArgs * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IPropertyChangedEventArgs * This);
/* [propget] */ HRESULT ( STDMETHODCALLTYPE *get_PropertyName )(
IPropertyChangedEventArgs * This,
UINT bufferSize,
/* [annotation][out][retval] */
_Out_writes_z_(bufferSize) WCHAR *propertyName);
END_INTERFACE
} IPropertyChangedEventArgsVtbl;
interface IPropertyChangedEventArgs
{
CONST_VTBL struct IPropertyChangedEventArgsVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IPropertyChangedEventArgs_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IPropertyChangedEventArgs_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IPropertyChangedEventArgs_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IPropertyChangedEventArgs_get_PropertyName(This,bufferSize,propertyName) \
( (This)->lpVtbl -> get_PropertyName(This,bufferSize,propertyName) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IPropertyChangedEventArgs_INTERFACE_DEFINED__ */
/* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,68 @@
#pragma once
#include <memory>
#include "NuiSensor.h"
#include "Lockable.h"
namespace Xbox { namespace Kinect { class NuiSensor; } }
class KinectExposure
{
public:
KinectExposure() = default;
// Fully automatic exposure setting.
// Exposure compensation: negative value gives an underexposed image,
// positive gives an overexposed image.
void SetAutoExposure(float exposure_compensation = 0);
// Sets a pseudo-exposure time in ms, value in range [0.0, 640] ms.
//
// The actual frame integration time is set to a multiple of fluorescent light period
// that is shorter than the requested time e.g. requesting 16 ms will set 10 ms
// in Australia (100Hz), 8.33 ms in USA (120Hz).
// The gain is automatically set to compensate for the reduced integration time.
//
// Requesting less than a single fluorescent light period will set the integration time
// to the requested value.
//
// To set the shortest non-flickering integration period for any country, simply set
// a pseudo-exposure time of between (10.0, 16.667) ms, which will automatically drop
// the integration time to 10 or 8.3 ms depending on country, while setting the analog
// gain control to a brighter value.
void SetSemiAutoExposure(float pseudo_exposure_time_ms);
// Manually set true exposure time and analog gain.
void SetManualExposure(float integration_time_ms, float analog_gain);
// Use one of the SET commands.
void SetFloat(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command, float value);
void SetUint(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command, uint32_t value);
// Use one of the GET commands.
uint32_t GetCommand(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command);
float GetCommandFloat(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command);
private:
LockableSharedPtr<Xbox::Kinect::NuiSensor> _sensor;
void Connect();
//private Dictionary<NUISENSOR_RGB_COMMAND_TYPE, uint> GetCommands(NUISENSOR_RGB_COMMAND_TYPE[] commands)
//{
// NUISENSOR_RGB_CHANGE_STREAM_SETTING setting;
// NUISENSOR_RGB_CHANGE_STREAM_SETTING_REPLY reply;
// setting.SequenceId = 0;
// setting.Commands = commands.Select(command = > new NUISENSOR_RGB_CHANGE_SETTING_CMD{ Cmd = (uint)command, Arg = 0 }).ToArray();
// lock(_sensor)
// {
// _sensor.ColorChangeCameraSettings(ref setting, out reply);
// }
// return commands.Zip(reply.Status, (c, r) = > { return Tuple.Create(c, r.Data); }).ToDictionary(t = > t.Item1, t = > t.Item2);
//}
uint32_t SetCommand(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command, uint32_t argument);
void SetCommand(Xbox::Kinect::NUISENSOR_RGB_COMMAND_TYPE command, float argument);
};
@@ -0,0 +1,108 @@
#pragma once
#ifndef LOCKABLE_H_
#define LOCKABLE_H_
#include <memory>
#include <mutex>
// Acts like a pointer to the locked object, but holds a lock for the given variable.
template<typename T>
class Locked
{
public:
Locked(T& obj, std::mutex& mutex) : _obj(obj), _mutex(mutex) { _mutex.lock(); }
Locked& operator=(const Locked&) = delete;
~Locked() { _mutex.unlock(); }
// Access members of the locked value.
const T* operator->() const noexcept { return &_obj; }
// Access members of the locked value.
T* operator->() noexcept { return &_obj; }
// Access the locked value.
const T& operator*() const noexcept { return _obj; }
// Access the locked value.
T& operator*() noexcept { return _obj; }
private:
T& _obj;
std::mutex& _mutex;
};
// Lockable value type.
template<typename T>
class Lockable
{
public:
// Only exists if T() exists.
Lockable() = default;
explicit Lockable(T obj) : _obj(std::move(obj)) {}
// Lock-guards the value for the lifetime of the returned object.
auto lock() const noexcept { return Locked<const T>(_obj, _mutex); }
// Lock-guards the value for the lifetime of the returned object.
auto lock() noexcept { return Locked<T>(_obj, _mutex); }
private:
T _obj;
mutable std::mutex _mutex;
};
// Acts like a shared_ptr, but holds a lock for the given pointer.
template<typename TPtr>
class LockedPtr
{
public:
LockedPtr(TPtr& obj, std::mutex& mutex) : _obj(obj), _mutex(mutex) { _mutex.lock(); }
LockedPtr& operator=(const LockedPtr&) = delete;
~LockedPtr() { _mutex.unlock(); }
// Access members of the locked shared_ptr.
auto* operator->() const noexcept { return _obj.get(); }
// Dereference the locked shared_ptr.
auto& operator*() const noexcept { return *_obj; }
// Test if the locked shared_ptr is null.
explicit operator bool() const noexcept { return bool(_obj); }
// Assign to the locked shared_ptr (assigns the shared_ptr, not the inner T value).
void operator=(TPtr obj) { _obj = std::move(obj); }
// Reset the locked shared_ptr.
void reset() noexcept { _obj.reset(); }
// Get the pointer type.
// WARNING: this is potentially unsafe since the data can be passed around unlocked.
TPtr value() const noexcept { return _obj; }
private:
TPtr& _obj;
std::mutex& _mutex;
};
// Lockable templated pointer type.
template<typename TPtr>
class LockablePtr
{
public:
LockablePtr()
: _obj()
, _mutex(std::make_shared<std::mutex>())
{
}
explicit LockablePtr(TPtr obj)
: _obj(std::move(obj))
, _mutex(std::make_shared<std::mutex>())
{
}
// Lock-guards the pointer for the lifetime of the returned object.
auto lock() const noexcept { return LockedPtr<const TPtr>(_obj, *_mutex); }
// Lock-guards the pointer for the lifetime of the returned object.
auto lock() noexcept { return LockedPtr<TPtr>(_obj, *_mutex); }
private:
TPtr _obj;
mutable std::shared_ptr<std::mutex> _mutex; // Shared so object is copyable e.g. TPtr is shared_ptr<T>
};
template<typename T>
using LockableSharedPtr = LockablePtr<std::shared_ptr<T>>;
template<typename T>
using LockableUniquePtr = LockablePtr<std::unique_ptr<T>>;
#endif // LOCKABLE_H_
@@ -0,0 +1,479 @@
#pragma once
#include <Windows.h>
#include <Ole2.h>
#include <stdio.h>
#include <Kinect.h>
#include <Kinect.Face.h>
#include <KinectExposure.h>
namespace NeoKinect
{
constexpr unsigned int KinectColorWidth = 1920;
constexpr unsigned int KinectColorHeight = 1080;
constexpr unsigned int KinectDepthWidth = 512;
constexpr unsigned int KinectDepthHeight = 424;
constexpr unsigned int KinectBodyCount = BODY_COUNT;
constexpr unsigned int KinectJointCount = JointType_Count;
struct Vector2
{
float x, y;
Vector2() : x(0.f), y(0.f) {}
Vector2(float xy) : x(xy), y(xy) {}
Vector2(float x, float y) : x(x), y(y) {}
explicit Vector2(const DepthSpacePoint& dsp) : x(dsp.X), y(dsp.Y) {}
explicit Vector2(const ColorSpacePoint& csp) : x(csp.X), y(csp.Y) {}
explicit Vector2(const PointF& pf) : x(pf.X), y(pf.Y) {}
template<typename T>
inline Vector2& operator=(const T& b);
inline DepthSpacePoint toDepthSpacePoint() const;
inline ColorSpacePoint toColorSpacePoint() const;
};
struct Vector3
{
float x, y, z;
Vector3() : x(0.f), y(0.f), z(0.f) {}
Vector3(float xyz) : x(xyz), y(xyz), z(xyz) {}
Vector3(float x, float y, float z) : x(x), y(y), z(z) {}
explicit Vector3(const CameraSpacePoint& csp) : x(csp.X), y(csp.Y), z(csp.Z) {}
inline Vector3& operator=(const CameraSpacePoint& b);
inline Vector3& operator/=(const float& b);
inline const Vector3 operator/(const float& b) const;
inline Vector3& operator*=(const float& b);
inline const Vector3 operator*(const float& b) const;
inline bool IsZero() const;
float magnitude() const; // not inline as it uses math header and I didn't want to polute the headers
inline Vector3 normalized() const;
inline CameraSpacePoint toCameraSpacePoint() const;
};
enum class KinectFrameType : BYTE
{
Color = 0,
Depth = 1,
Body = 2,
BodyIndex = 3,
Infrared = 4,
LongExposureInfrared = 5,
Face = 6,
Count = 7
};
enum class KinectCoordinateSpace : BYTE
{
Camera = 0,
Depth = 1,
Color = 2,
Count = 3
};
enum class KinectPixelFormat : BYTE
{
B8G8R8A8 = 0,
G8 = 1,
G16 = 2,
Bayer = 3,
None = 4,
Count = 5
};
struct KinectJoint
{
Vector4 orientation;
CameraSpacePoint position;
TrackingState trackingState;
JointType type;
};
struct KinectBodyEdges
{
bool left, right, top, bottom;
};
struct KinectBody
{
UINT64 trackingId;
bool isTracked, isRestricted;
KinectBodyEdges clippedEdges;
HandState handLeftState;
TrackingState handLeftTrackingState;
HandState handRightState;
TrackingState handRightTrackingState;
TrackingState leanTrackingState;
Vector2 lean;
KinectJoint joints[JointType_Count];
};
struct KinectFacePoints
{
Vector2 leftEye;
Vector2 rightEye;
Vector2 nose;
Vector2 leftMouthCorner;
Vector2 rightMouthCorner;
};
struct KinectFace
{
UINT64 trackingId;
// face bounding box in color space
RectI boxColor;
// face bounding box in infrared space
RectI boxInfrared;
// face rotation in quaternion
Vector4 rotation;
// face pivot point. The same as the skeleton head joint. It's here for conveninence.
CameraSpacePoint pivot;
// face alignment points in color space
KinectFacePoints pointsColor;
// face alignment points in infrared space
KinectFacePoints pointsInfrared;
DetectionResult isEngaged;
DetectionResult isHappy;
DetectionResult isLookingAway;
DetectionResult isMouthMoved;
DetectionResult isMouthOpen;
DetectionResult isLeftEyeClosed;
DetectionResult isRightEyeClosed;
DetectionResult isWearingGlasses;
bool bIsTracked;
};
struct FrameDescription
{
bool valid;
float diagonalFieldOfView,
horizontalFieldOfView,
verticalFieldOfView;
UINT bytesPerPixel;
UINT lengthInPixels;
int width, height;
FrameDescription() : valid(false) {}
};
class KinectSensor
{
public:
KinectSensor();
~KinectSensor();
/*
Opens the Microsoft API to the sensor.
@return Is the sensor API working?
*/
bool InitSensor();
/*
Is the sensor on already?
It may take some time for the sensor to effectivelly turn on. Keep trying.
If it's taking too long, there's probably no connected sensor or it's not working.
@return True if the sensor is on.
*/
bool IsSensorAvailable();
/*
Is the Microsoft Kinect API responding?
@return True if the sensor API is working.
*/
bool IsSensorOpen();
/*
Shuts the sensor down and closes the Microsoft API to it.
@return True if it worked.
*/
bool UninitSensor();
/*
A Vector4 containing the floor normal (xyz) and height (w).
Valid only if frequently locking and unlocking Body frame. That's when
it gets updated.
@return A Vector4 containing the floor normal (xyz) and height (w).
*/
Vector4 GetFloorClipPlane();
/*
Uses the floor clip plane to calculate how much the sensor is tilted.
@return The sensor tilt in degrees. Looking down gives negative values.
*/
float GetSensorTilt();
FrameDescription GetFrameDescription(const KinectFrameType frameType) const;
bool SetUseFrame(const KinectFrameType frameType, const bool use = true);
bool GetIsUsingFrame(const KinectFrameType frameType) const;
bool LockLatestFrame(KinectFrameType frameType);
void UnlockLatestFrame(KinectFrameType frameType);
bool GetIsFrameLocked(KinectFrameType frameType) const;
bool GetLatestFrameData(const KinectFrameType frameType, BYTE *& buffer, const KinectPixelFormat pixelFormat = KinectPixelFormat::None);
bool GetLatestFrameData(KinectBody bodies[BODY_COUNT]);
bool GetLatestFrameData(KinectFace faces[BODY_COUNT]);
/*
Gets a frame remapped to another coordinate system.
All the remapping methods depend on the Depth frame. So make sure you're
frequently locking and unlocking it.
@return True if it worked.
*/
bool GetRemappedFrameData(
const KinectFrameType frameType, const KinectCoordinateSpace targetSpace,
BYTE *const buffer, const KinectPixelFormat pixelFormat);
/*
Gets a point remapped to another coordinate system.
All the remapping methods depend on the Depth frame. So make sure you're
frequently locking and unlocking it.
@return True if it worked.
*/
bool GetRemappedPoint(
const KinectCoordinateSpace fromSpace, const KinectCoordinateSpace toSpace,
const Vector2& srcPoint, Vector2& resultPoint);
bool GetRemappedPoint(
const KinectCoordinateSpace fromSpace, const KinectCoordinateSpace toSpace,
const Vector2& srcPoint, Vector3& resultPoint) const;
bool GetRemappedPoint(
const KinectCoordinateSpace fromSpace, const KinectCoordinateSpace toSpace,
const Vector3& srcPoint, Vector2& resultPoint) const;
/*
Samples distance from the Depth frame.
The pixel used will be the round result of X and Y.
Note: this only works if the Depth frame is used and is being locked and
unlocked frequently.
*/
UINT16 SampleDepthFrame(const Vector2& point);
/*
Samples distance from the Depth frame using a coordinate from the Color frame.
The pixel used will be the round result of X and Y after remapped to the Depth frame.
Note: this only works if the 'Depth' and 'Depth remapped to Color' frames are both
used and are being locked and unlocked frequently.
*/
UINT16 SampleDepthFromColorCoords(const Vector2& colorPoint);
/*
Fully automatic exposure setting.
@param exposureCompensation Negative value gives an underexposed image,
positive gives an overexposed image.
*/
void SetAutoExposure(float exposureCompensation = 0);
/*
Sets a pseudo-exposure time in ms.
The actual frame integration time is set to a multiple of fluorescent light period
that is shorter than the requested time e.g. requesting 16 ms will set 10 ms
in Australia (100Hz), 8.33 ms in USA (120Hz).
The gain is automatically set to compensate for the reduced integration time.
Requesting less than a single fluorescent light period will set the integration time
to the requested value.
To set the shortest non-flickering integration period for any country, simply set
a pseudo-exposure time of between (10.0, 16.667) ms, which will automatically drop
the integration time to 10 or 8.3 ms depending on country, while setting the analog
gain control to a brighter value.
@param pseudoExposureTime Pseudo-exposure time in ms. [0.0, 640]ms
*/
void SetSemiAutoExposure(float pseudoExposureTime);
/*
Manually set true exposure time and analog gain.
@param frameExposureTime Time of exposure for each frame, in ms. [0.0, 640]ms
@param analogGain Exposure analog gain.
*/
void SetManualExposure(float frameExposureTime, float analogGain);
private:
IKinectSensor *pSensor; // Kinect sensor
//IMultiSourceFrameReader *pMultiFrameReader;
//IMultiSourceFrame *pMultiFrame;
KinectExposure exposureControl;
// Frame types
#define FRAME_VAR(name) I ##name## Frame *p ##name## Frame; I ##name## FrameReader *p ##name## FrameReader;
FRAME_VAR(Body);
FRAME_VAR(BodyIndex);
FRAME_VAR(Color);
FRAME_VAR(Depth);
FRAME_VAR(Infrared);
FRAME_VAR(LongExposureInfrared);
#undef FRAME_VAR
// Face frame resources
/* Features we'll use from face frames */
static const DWORD cFaceFrameFeatures =
FaceFrameFeatures_FaceEngagement
| FaceFrameFeatures_Happy
| FaceFrameFeatures_LookingAway
| FaceFrameFeatures_Glasses
| FaceFrameFeatures_LeftEyeClosed
| FaceFrameFeatures_RightEyeClosed
| FaceFrameFeatures_MouthMoved
| FaceFrameFeatures_MouthOpen
| FaceFrameFeatures_RotationOrientation
| FaceFrameFeatures_PointsInColorSpace
| FaceFrameFeatures_PointsInInfraredSpace
| FaceFrameFeatures_BoundingBoxInColorSpace
| FaceFrameFeatures_BoundingBoxInInfraredSpace;
IFaceFrameSource *pFaceFrameSources[BODY_COUNT];
IFaceFrameReader *pFaceFrameReaders[BODY_COUNT];
IFaceFrame *pFaceFrames[BODY_COUNT];
// Converts between depth, color and 3d coords
ICoordinateMapper *pMapper;
DepthSpacePoint *pColorMappedToDepth;
bool bIsColorMappedToDepthDirty;
/* We keep a copy of the latest depth frame so the user can convert points
between spaces anytime, not only when the depth frame is locked.
This copy is updated everytime the frame is locked. Because of it, some
coordinate space convertions may not work if the depth frame is not in use
nor locked frequently. */
UINT16 *pDepthRawCopy;
IBody *bodies[BODY_COUNT];
Joint joints[JointType_Count]; // keep joints array in memory to avoid frequent allocations
JointOrientation jointOrientations[JointType_Count];
Vector4 floorClipPlane;
inline bool InitMapper();
inline void UpdateColorMappedToDepth();
inline int IndexFromXY(int pitch, float x, float y) const;
};
/* Print formatted string to the Output window */
void Printf(const char *szFormat, ...);
void LogFailedHResult(const HRESULT hr, const char *functionName, const int line, const char *action = "");
template <typename T>
inline void SafeRelease(T*& pointer);
template <typename T>
inline void SafeReleaseArray(T*& pointer);
/*-------------------------------------------------------------------------
Templates and inlines implementation
-------------------------------------------------------------------------*/
template<typename T>
Vector2& Vector2::operator=(const T& b)
{
if (this != &b)
{
this->x = b.X;
this->y = b.Y;
}
return *this;
}
DepthSpacePoint Vector2::toDepthSpacePoint() const
{
DepthSpacePoint b;
b.X = this->x;
b.Y = this->y;
return b;
}
ColorSpacePoint Vector2::toColorSpacePoint() const
{
ColorSpacePoint b;
b.X = this->x;
b.Y = this->y;
return b;
}
Vector3& Vector3::operator=(const CameraSpacePoint& b)
{
this->x = b.X;
this->y = b.Y;
this->z = b.Z;
return *this;
}
Vector3& Vector3::operator/=(const float& other)
{
x /= other;
y /= other;
z /= other;
return *this;
}
const Vector3 Vector3::operator/(const float& other) const
{
Vector3 result(*this);
return result /= other;
}
Vector3& Vector3::operator*=(const float& other)
{
x *= other;
y *= other;
z *= other;
return *this;
}
const Vector3 Vector3::operator*(const float& other) const
{
Vector3 result(*this);
return result *= other;
}
bool Vector3::IsZero() const
{
return x == 0.f && y == 0.f && z == 0.f;
}
Vector3 Vector3::normalized() const
{
if (IsZero())
return Vector3();
return (*this / magnitude());
}
CameraSpacePoint Vector3::toCameraSpacePoint() const
{
CameraSpacePoint b;
b.X = this->x;
b.Y = this->y;
b.Z = this->z;
return b;
}
template<typename T>
inline void SafeRelease(T*& pointer)
{
if (pointer)
{
pointer->Release();
}
pointer = nullptr;
}
template<typename T>
inline void SafeReleaseArray(T*& pointer)
{
if (pointer)
{
delete[] pointer;
}
pointer = nullptr;
}
}
@@ -0,0 +1,145 @@
// Conversion from the original C++/CLI implementation.
#pragma once
#include <vector>
typedef struct _NUISENSOR_HANDLE *NUISENSOR_HANDLE, **PNUISENSOR_HANDLE;
//using namespace System;
//using namespace System::Runtime::InteropServices;
namespace Xbox
{
namespace Kinect
{
enum NUISENSOR_RGB_COMMAND_TYPE
{
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_MODE = 0,
NUISENSOR_RGB_COMMAND_SET_INTEGRATION_TIME = 1,
NUISENSOR_RGB_COMMAND_GET_INTEGRATION_TIME = 2,
NUISENSOR_RGB_COMMAND_SET_WHITE_BALANCE_MODE = 10,
NUISENSOR_RGB_COMMAND_SET_RED_CHANNEL_GAIN = 11,
NUISENSOR_RGB_COMMAND_SET_GREEN_CHANNEL_GAIN = 12,
NUISENSOR_RGB_COMMAND_SET_BLUE_CHANNEL_GAIN = 13,
NUISENSOR_RGB_COMMAND_GET_RED_CHANNEL_GAIN = 14,
NUISENSOR_RGB_COMMAND_GET_GREEN_CHANNEL_GAIN = 15,
NUISENSOR_RGB_COMMAND_GET_BLUE_CHANNEL_GAIN = 16,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_TIME_MS = 17,
NUISENSOR_RGB_COMMAND_GET_EXPOSURE_TIME_MS = 18,
NUISENSOR_RGB_COMMAND_SET_DIGITAL_GAIN = 19,
NUISENSOR_RGB_COMMAND_GET_DIGITAL_GAIN = 20,
NUISENSOR_RGB_COMMAND_SET_ANALOG_GAIN = 21,
NUISENSOR_RGB_COMMAND_GET_ANALOG_GAIN = 22,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_COMPENSATION = 23,
NUISENSOR_RGB_COMMAND_GET_EXPOSURE_COMPENSATION = 24,
NUISENSOR_RGB_COMMAND_SET_ACS = 25,
NUISENSOR_RGB_COMMAND_GET_ACS = 26,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_MODE = 27,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONES = 28,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_0_WEIGHT = 29,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_1_WEIGHT = 30,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_2_WEIGHT = 31,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_3_WEIGHT = 32,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_4_WEIGHT = 33,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_5_WEIGHT = 34,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_6_WEIGHT = 35,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_7_WEIGHT = 36,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_8_WEIGHT = 37,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_9_WEIGHT = 38,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_10_WEIGHT = 39,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_11_WEIGHT = 40,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_12_WEIGHT = 41,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_13_WEIGHT = 42,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_14_WEIGHT = 43,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_15_WEIGHT = 44,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_16_WEIGHT = 45,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_17_WEIGHT = 46,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_18_WEIGHT = 47,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_19_WEIGHT = 48,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_20_WEIGHT = 49,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_21_WEIGHT = 50,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_22_WEIGHT = 51,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_23_WEIGHT = 52,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_24_WEIGHT = 53,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_25_WEIGHT = 54,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_26_WEIGHT = 55,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_27_WEIGHT = 56,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_28_WEIGHT = 57,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_29_WEIGHT = 58,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_30_WEIGHT = 59,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_31_WEIGHT = 60,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_32_WEIGHT = 61,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_33_WEIGHT = 62,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_34_WEIGHT = 63,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_35_WEIGHT = 64,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_36_WEIGHT = 65,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_37_WEIGHT = 66,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_38_WEIGHT = 67,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_39_WEIGHT = 68,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_40_WEIGHT = 69,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_41_WEIGHT = 70,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_42_WEIGHT = 71,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_43_WEIGHT = 72,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_44_WEIGHT = 73,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_45_WEIGHT = 74,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_46_WEIGHT = 75,
NUISENSOR_RGB_COMMAND_SET_EXPOSURE_METERING_ZONE_47_WEIGHT = 76,
NUISENSOR_RGB_COMMAND_SET_MAX_ANALOG_GAIN_CAP = 77,
NUISENSOR_RGB_COMMAND_SET_MAX_DIGITAL_GAIN_CAP = 78,
NUISENSOR_RGB_COMMAND_SET_FLICKER_FREE_FREQUENCY = 79,
NUISENSOR_RGB_COMMAND_GET_EXPOSURE_MODE = 80,
NUISENSOR_RGB_COMMAND_GET_WHITE_BALANCE_MODE = 81,
NUISENSOR_RGB_COMMAND_SET_FRAME_RATE = 82,
NUISENSOR_RGB_COMMAND_GET_FRAME_RATE = 83,
// This range is reserved. Do not re-use.
NUISENSOR_RGB_COMMAND_RESERVED_BASE = 400,
NUISENSOR_RGB_COMMAND_RESERVED_END = NUISENSOR_RGB_COMMAND_RESERVED_BASE + 200,
// End of reserved region
};
struct NUISENSOR_RGB_CHANGE_SETTING_CMD
{
uint32_t Cmd;
uint32_t Arg;
};
struct NUISENSOR_RGB_CHANGE_STREAM_SETTING
{
uint32_t SequenceId;
std::vector<NUISENSOR_RGB_CHANGE_SETTING_CMD> Commands;
};
struct NUISENSOR_RGB_CHANGE_STREAM_SETTING_REPLY_STATUS
{
uint32_t Status;
uint32_t Data;
};
struct NUISENSOR_RGB_CHANGE_STREAM_SETTING_REPLY
{
uint32_t CommandListStatus;
std::vector<NUISENSOR_RGB_CHANGE_STREAM_SETTING_REPLY_STATUS> Status;
};
class NuiSensor
{
public:
NuiSensor();
~NuiSensor();
void Shutdown();
void ColorChangeCameraSettings(const NUISENSOR_RGB_CHANGE_STREAM_SETTING& settings, NUISENSOR_RGB_CHANGE_STREAM_SETTING_REPLY* p_reply);
private:
void TestResult(int success);
NUISENSOR_HANDLE _sensor = nullptr;
};
}
}