Mercurial > hg > Game > Kinect
comparison test/main.cc @ 4:edf80c055589 default tip
kinect run on Cerium
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Feb 2011 14:44:56 +0900 |
parents | main.cc@7e112b536f0a |
children |
comparison
equal
deleted
inserted
replaced
3:7e112b536f0a | 4:edf80c055589 |
---|---|
1 #include <stdio.h> | |
2 #include <XnOpenNI.h> | |
3 #include <XnCppWrapper.h> | |
4 #include <XnVNite.h> | |
5 | |
6 #include "KinectTrack.h" | |
7 | |
8 #define INIT_XML_PATH "./kinect.xml" | |
9 | |
10 void checkRC(const XnStatus &rc, const char *what) { | |
11 if (rc != XN_STATUS_OK) { | |
12 printf("%s faild: %s\n", what, xnGetStatusString(rc)); | |
13 } | |
14 } | |
15 | |
16 void checkErrors(XnStatus &rc, xn::EnumerationErrors &errors, const char *what) { | |
17 if (rc == XN_STATUS_NO_NODE_PRESENT) { | |
18 XnChar strError[1024]; | |
19 errors.ToString(strError, 1024); | |
20 printf("%s\n", strError); | |
21 } | |
22 } | |
23 | |
24 SessionState NIState::gSessionState = NOT_IN_SESSION; | |
25 XnBool NIState::gBDrawDepthMap = true; | |
26 void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) { | |
27 printf("Session start: (%f, %f, %f)\n", ptPosition.X, ptPosition.Y, ptPosition.Z); | |
28 gSessionState = IN_SESSION; | |
29 } | |
30 void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) { | |
31 printf("Session end\n"); | |
32 gSessionState = NOT_IN_SESSION; | |
33 } | |
34 void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, | |
35 XnFloat fProgress, void *userCxt) { | |
36 printf("Focus progress: %s @(%f, %f, %f): %f\n", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); | |
37 } | |
38 void NIState::XN_CALLBACK_TYPE noHands(void *UserCxt) { | |
39 if (gSessionState != NOT_IN_SESSION) { | |
40 printf("Quick refocus\n"); | |
41 gSessionState = QUICK_REFOCUS; | |
42 } | |
43 } | |
44 | |
45 int main(int argc, char *argv[]) { | |
46 xn::Context gContext; | |
47 xn::EnumerationErrors errors; | |
48 XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors); | |
49 checkErrors(rc, errors, "InitFromXMLFile"); | |
50 checkRC(rc, "InitFromXMLFile"); | |
51 | |
52 xn::DepthGenerator gDepthGenerator; | |
53 rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator); | |
54 checkRC(rc, "Find depth generator"); | |
55 | |
56 xn::HandsGenerator gHandsGenerator; | |
57 rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator); | |
58 checkRC(rc, "Find hands generator"); | |
59 XnVSessionManager *gPSessionManager = new XnVSessionManager(); | |
60 rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); | |
61 checkRC(rc, "SessionManager::Initialize"); | |
62 | |
63 gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); | |
64 | |
65 XnVPointDrawer *gPDrawer = new XnVPointDrawer(20, gDepthGenerator); | |
66 XnVFlowRouter *gPFlowRouter = new XnVFlowRouter; | |
67 gPFlowRouter->SetActive(gPDrawer); | |
68 | |
69 gPSessionManager->AddListener(gPFlowRouter); | |
70 | |
71 gPDrawer->RegisterNoPoints(NULL, NIState::noHands); | |
72 gPDrawer->setDepthMap(NIState::gBDrawDepthMap); | |
73 | |
74 rc = gContext.StartGeneratingAll(); | |
75 checkRC(rc, "StartGenerating"); | |
76 | |
77 while (true) { | |
78 gContext.WaitAndUpdateAll(); | |
79 gPSessionManager->Update(&gContext); | |
80 float x, y, z; | |
81 int error = gPDrawer->getPosition(x, y, z); | |
82 if (error > 0) { | |
83 printf("%f, %f, %f\n", x, y, z); | |
84 } | |
85 | |
86 //usleep(10); | |
87 } | |
88 | |
89 return 0; | |
90 } |