Mercurial > hg > Game > Kinect
changeset 0:1478aad947a6
init
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 31 Jan 2011 03:46:10 +0900 |
parents | |
children | 2afd5c6cc8d2 |
files | Makefile kinect.xml main.cc |
diffstat | 3 files changed, 110 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,16 @@ +CC = g++ +CFLAGS = -Wall -g -O2 +INCLUDE = -I/usr/include/ni -I/usr/include/nite +LIBS = -lOpenNI -lXnVNite +OBJS = main.o +TARGET = kinect + +.SUFFIXES: .cc .o + +all: $(OBJS) + $(CC) $(CFLAGS) $(INCLUDE) $(LIBS) $(OBJS) -o $(TARGET) +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ +clean: + rm *.o + rm $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kinect.xml Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,24 @@ +<OpenNI> + <Licenses> + <License vendor="PrimeSense" key="insert key here"/> + </Licenses> + <Log writeToConsole="true" writeToFile="false"> + <!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) --> + <LogLevel value="3"/> + <Masks> + <Mask name="ALL" on="false"/> + </Masks> + <Dumps> + </Dumps> + </Log> + <ProductionNodes> + <Node type="Depth"> + <Configuration> + <MapOutputMode xRes="640" yRes="480" FPS="30"/> + <Mirror on="true"/> + </Configuration> + </Node> + <Node type="Gesture" /> + <Node type="Hands" /> + </ProductionNodes> +</OpenNI>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cc Mon Jan 31 03:46:10 2011 +0900 @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <XnOpenNI.h> +#include <XnCppWrapper.h> +#include <XnVNite.h> + +#define INIT_XML_PATH "./kinect.xml" + +typedef enum { + IN_SESSION, + NOT_IN_SESSION, + QUICK_REFOCUS +} SessionState; + +void checkRC(const XnStatus &rc, const char *what) { + if (rc != XN_STATUS_OK) { + printf("%s faild: %s\n", what, xnGetStatusString(rc)); + } +} + +void checkErrors(XnStatus &rc, xn::EnumerationErrors &errors, const char *what) { + if (rc == XN_STATUS_NO_NODE_PRESENT) { + XnChar strError[1024]; + errors.ToString(strError, 1024); + printf("%s\n", strError); + } +} + +class NIState { +public: + static SessionState gSessionState; + static void XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt); + static void XN_CALLBACK_TYPE sessionEnding(void *userCxt); + static void XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, + XnFloat fProgress, void *userCxt); +}; +SessionState NIState::gSessionState = NOT_IN_SESSION; +void NIState::XN_CALLBACK_TYPE sessionStarting(const XnPoint3D &ptPosition, void *userCxt) { + printf("Session start: (%f, %f, %f)\n)", ptPosition.X, ptPosition.Y, ptPosition.Z); + gSessionState = IN_SESSION; +} +void NIState::XN_CALLBACK_TYPE sessionEnding(void *userCxt) { + printf("Session end\n"); + gSessionState = NOT_IN_SESSION; +} +void NIState::XN_CALLBACK_TYPE focusProgress(const XnChar *strFocus, const XnPoint3D &ptPosition, + XnFloat fProgress, void *userCxt) { + //printf("Focus progress: %s @(%f, %f, %f): %f\n)", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); +} + +int main(int argc, char *argv[]) { + xn::Context gContext; + xn::EnumerationErrors errors; + XnStatus rc = gContext.InitFromXmlFile(INIT_XML_PATH, &errors); + checkErrors(rc, errors, "InitFromXMLFile"); + checkRC(rc, "InitFromXMLFile"); + + xn::DepthGenerator gDepthGenerator; + rc = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH, gDepthGenerator); + checkRC(rc, "Find depth generator"); + + xn::HandsGenerator gHandsGenerator; + rc = gContext.FindExistingNode(XN_NODE_TYPE_HANDS, gHandsGenerator); + checkRC(rc, "Find hands generator"); + XnVSessionManager *gPSessionManager = new XnVSessionManager(); + rc = gPSessionManager->Initialize(&gContext, "Click,Wave", "RaiseHand"); + checkRC(rc, "SessionManager::Initialize"); + gPSessionManager->RegisterSession(NULL, NIState::sessionStarting, NIState::sessionEnding, NIState::focusProgress); + + return 0; +}