以下代码是根据这里改编成C++版的,实现思路上相同,但是细节有差异,不影响理解
#include<iostream>
#include<Windows.h>
#include<NuiApi.h>
#include<ctime>
#include<cassert>
#include<process.h>
#pragma comment(lib,"kinect10.lib")
using namespace std;
HANDLE DetectionEvent = CreateEvent( NULL, false, false, NULL );
// 记录手势当前位置
enum GesturePos{
NonePos = 0,
Left,
Right,
Neutral
};
// 判断识别状态
enum DetectionState{
NoneState = 0,
Success,
Failed,
InProgress
};
// 判断手势需要的数据
struct DataState{
GesturePos Pos; // 每个人的左右手
DetectionState State;
int times;
time_t timestamp;
void Reset()
{
Pos = GesturePos::NonePos;
State = DetectionState::NoneState;
times = 0;
timestamp = 0;
}
};
// 完成手势判断逻辑功能
class GestureDetection{
public:
GestureDetection( float neutral_threshold, int times, double difftimes )
: neutral_threshold( neutral_threshold )
, times(times)
, difftimes(difftimes)
, left_hand(0)
, right_hand(1)
{
for( int i = 0; i < NUI_SKELETON_COUNT; i++ )
{
wave_datas[i][left_hand].Reset();
wave_datas[i][right_hand].Reset();
}
}
// 功能:循环接收骨骼数据,如果识别出为挥手动作则输出:success,
// 识别失败