0
|
1 #include <stdio.h>
|
|
2 #include <XnOpenNI.h>
|
|
3 #include <XnCppWrapper.h>
|
|
4 #include <XnVNite.h>
|
|
5
|
|
6 #define INIT_XML_PATH "./kinect.xml"
|
|
7
|
|
8 typedef enum {
|
|
9 IN_SESSION,
|
|
10 NOT_IN_SESSION,
|
|
11 QUICK_REFOCUS
|
|
12 } SessionState;
|
|
13
|
|
14 void checkRC(const XnStatus &rc, const char *what) {
|
|
15 if (rc != XN_STATUS_OK) {
|
|
16 printf("%s faild: %s\n", what, xnGetStatusString(rc));
|
|
17 }
|
|
18 }
|
|
19
|
|
20 void checkErrors(XnStatus &rc, xn::EnumerationErrors &errors, const char *what) {
|
|
21 if (rc == XN_STATUS_NO_NODE_PRESENT) {
|
|
22 XnChar strError[1024];
|
|
23 errors.ToString(strError, 1024);
|
|
24 printf("%s\n", strError);
|
|
25 }
|
|
26 }
|
|
27
|
|
28 class NIState {
|
|
29 public:
|
|
30 static SessionState gSessionState;
|
|
31 static void XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt);
|
|
32 static void XN_CALLBACK_TYPE sessionEnding(void *userCxt);
|
|
33 static void XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition,
|
|
34 XnFloat fProgress, void *userCxt);
|
|
35 };
|
|
36 SessionState NIState::gSessionState = NOT_IN_SESSION;
|
|
37 void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) {
|
|
38 printf("Session start: (%f, %f, %f)\n)", ptPosition.X, ptPosition.Y, ptPosition.Z);
|
|
39 gSessionState = IN_SESSION;
|
|
40 }
|
|
41 void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) {
|
|
42 printf("Session end\n");
|
|
43 gSessionState = NOT_IN_SESSION;
|
|
44 }
|
|
45 void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition,
|
|
46 XnFloat fProgress, void *userCxt) {
|
|
47 //printf("Focus progress: %s @(%f, %f, %f): %f\n)", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress);
|
|
48 }
|
|
49
|
|
50 int main(int argc, char *argv[]) {
|
|
51 xn::Context gContext;
|
|
52 xn::EnumerationErrors errors;
|
|
53 XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors);
|
|
54 checkErrors(rc, errors, "InitFromXMLFile");
|
|
55 checkRC(rc, "InitFromXMLFile");
|
|
56
|
|
57 xn::DepthGenerator gDepthGenerator;
|
|
58 rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator);
|
|
59 checkRC(rc, "Find depth generator");
|
|
60
|
|
61 xn::HandsGenerator gHandsGenerator;
|
|
62 rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator);
|
|
63 checkRC(rc, "Find hands generator");
|
|
64 XnVSessionManager *gPSessionManager = new XnVSessionManager();
|
|
65 rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand");
|
|
66 checkRC(rc, "SessionManager::Initialize");
|
|
67 gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress);
|
|
68
|
|
69 return 0;
|
|
70 }
|