-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjknect.h
More file actions
executable file
·150 lines (128 loc) · 5.3 KB
/
jknect.h
File metadata and controls
executable file
·150 lines (128 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/****************************************************************************
* *
* Hugo Ribeira *
* Copyright (C) 2012 *
* *
* This file is part of SimpleKinect. *
* *
* SimpleKinect is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* SimpleKinect is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
#ifndef JKNECT
#define JKNECT
#include <XnCppWrapper.h>
#include <exception>
#include <string>
#define SAMPLE_XML_PATH "./Data/SamplesConfig.xml"
#define SAMPLE_XML_PATH_LOCAL "SamplesConfig.xml"
#define MAX_NUM_USERS 15
class SimpleKinect{
protected:
//Variable Declaration
xn::Context g_Context;
xn::ScriptNode g_scriptNode;
XnStatus nRetVal;
xn::EnumerationErrors errors;
const char *fn;
void checkrc(std::string what)
{
if (nRetVal != XN_STATUS_OK)
throw std::exception(std::string(what + xnGetStatusString(nRetVal)).c_str());
}
public:
SimpleKinect(const std::string xmldir = SAMPLE_XML_PATH);
virtual ~SimpleKinect()
{
g_scriptNode.Release();
g_Context.Release();
}
private:
XnBool fileExists(const char *fn)
{
XnBool exists;
xnOSDoesFileExist(fn, &exists);
return exists;
}
//No Copy, Assignment...
SimpleKinect(const SimpleKinect &src);
SimpleKinect& operator=(const SimpleKinect &src);
};
class SimpleKSkeleton : public SimpleKinect{
protected:
static xn::DepthGenerator g_DepthGenerator;
static xn::UserGenerator g_UserGenerator;
static XnBool g_bNeedPose;
static XnChar g_strPose[20];
public:
SimpleKSkeleton(const std::string xmldir = SAMPLE_XML_PATH);
//DEV
static void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& /*generator*/, XnUserID nId, void* /*pCookie*/){
XnUInt32 epochTime = 0;
xnOSGetEpochTime(&epochTime);
printf("%d New User %d\n", epochTime, nId);
// New user found
if (g_bNeedPose){
g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
}
else{
g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
}
}
static void XN_CALLBACK_TYPE User_LostUser(xn::UserGenerator& /*generator*/, XnUserID nId, void* /*pCookie*/)
{
XnUInt32 epochTime = 0;
xnOSGetEpochTime(&epochTime);
printf("%d Lost user %d\n", epochTime, nId);
}
static void XN_CALLBACK_TYPE UserPose_PoseDetected(xn::PoseDetectionCapability& /*capability*/, const XnChar* strPose, XnUserID nId, void* /*pCookie*/)
{
XnUInt32 epochTime = 0;
xnOSGetEpochTime(&epochTime);
printf("%d Pose %s detected for user %d\n", epochTime, strPose, nId);
g_UserGenerator.GetPoseDetectionCap().StopPoseDetection(nId);
g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
}
static void XN_CALLBACK_TYPE UserCalibration_CalibrationStart(xn::SkeletonCapability& /*capability*/, XnUserID nId, void* /*pCookie*/)
{
XnUInt32 epochTime = 0;
xnOSGetEpochTime(&epochTime);
printf("%d Calibration started for user %d\n", epochTime, nId);
}
static void XN_CALLBACK_TYPE UserCalibration_CalibrationComplete(xn::SkeletonCapability& /*capability*/, XnUserID nId, XnCalibrationStatus eStatus, void* /*pCookie*/)
{
XnUInt32 epochTime = 0;
xnOSGetEpochTime(&epochTime);
if (eStatus == XN_CALIBRATION_STATUS_OK){
// Calibration succeeded
printf("%d Calibration complete, start tracking user %d\n", epochTime, nId);
g_UserGenerator.GetSkeletonCap().StartTracking(nId);
}
else{
// Calibration failed
printf("%d Calibration failed for user %d\n", epochTime, nId);
if(eStatus==XN_CALIBRATION_STATUS_MANUAL_ABORT){
printf("Manual abort occured, stop attempting to calibrate!");
return;
}
if (g_bNeedPose){
g_UserGenerator.GetPoseDetectionCap().StartPoseDetection(g_strPose, nId);
}
else{
g_UserGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
}
}
}
//UNDEV
};
#endif