Commits

schlangen committed 0d8563b

recent test with openni, nite and opencv to display skeleton data. based on OSCeleton.cpp

Comments (0)

Files changed (2)

FirstTest/Makefile

+CFLAGS = `pkg-config --cflags opencv`
+LFLAGS = `pkg-config --libs opencv`
+
+all: clean FirstTest
+
+clean:
+	rm -f FirstTest
+
+FirstTest:
+	g++ main.cpp -O3 -Wno-write-strings  -I/usr/X11/include -I/usr/include/ni $(CFLAGS) -LOpenNI -lstdc++ -L/usr/X11/lib $(LFLAGS)  -o FirstTest
+	
+

FirstTest/main.cpp

+/***********************************************************************
+
+    based on OSCeleton.cpp from OSCeleton project
+
+
+    OSCeleton - OSC proxy for kinect skeleton data.
+    Copyright (C) <2010>  <Sensebloom lda.>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+***********************************************************************/
+
+#include <cstdio>
+#include <csignal>
+#include <iostream>
+#include <fstream>
+
+#include <XnCppWrapper.h>
+
+#include "cv.h"
+#include "highgui.h"
+
+float jointCoords[3];
+float jointOrients[9];
+
+// caches all joint coords
+float allJointCoords[24][3];
+
+float posConfidence;
+float orientConfidence;
+
+//Multipliers for coordinate system. This is useful if you use
+//software like animata, that needs OSC messages to use an arbitrary
+//coordinate system.
+double mult_x = 1;
+double mult_y = 1;
+double mult_z = 1;
+
+//Offsets for coordinate system. This is useful if you use software
+//like animata, that needs OSC messages to use an arbitrary coordinate
+//system.
+double off_x = 0.0;
+double off_y = 0.0;
+double off_z = 0.0;
+
+// hand data
+float handCoords[3];
+bool haveHand = false;
+
+bool kitchenMode = false;
+bool handMode = false;
+bool mirrorMode = true;
+bool play = false;
+bool record = false;
+bool sendRot = false;
+bool filter = false;
+bool preview = false;
+bool raw = false;
+bool filterLowConfidence = false;
+bool realworld = false;
+bool debugFacts = false;
+bool debugCSV = false;
+bool sendOrient = false;
+int nDimensions = 3;
+
+
+
+xn::Context context;
+xn::DepthGenerator depth;
+xn::DepthMetaData depthMD;
+xn::UserGenerator userGenerator;
+xn::HandsGenerator handsGenerator;
+xn::GestureGenerator gestureGenerator;
+
+XnChar g_strPose[20] = "";
+#define GESTURE_TO_USE "Wave"
+
+
+void visualize_current_data();
+
+
+//gesture callbacks
+void XN_CALLBACK_TYPE Gesture_Recognized(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie) {
+    printf("Gesture recognized: %s\n", strGesture);
+    gestureGenerator.RemoveGesture(strGesture);
+    handsGenerator.StartTracking(*pEndPosition);
+}
+
+void XN_CALLBACK_TYPE Gesture_Process(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie) {
+  std::cout <<  "gesture process" <<std::endl;
+}
+
+//hand callbacks new_hand, update_hand, lost_hand
+void XN_CALLBACK_TYPE new_hand(xn::HandsGenerator &generator, XnUserID nId, const XnPoint3D *pPosition, XnFloat		, void *pCookie) {
+	printf("New Hand %d\n", nId);
+	std::cout <<  std::endl;
+	
+}
+void XN_CALLBACK_TYPE lost_hand(xn::HandsGenerator &generator, XnUserID nId, XnFloat fTime, void *pCookie) {
+	printf("Lost Hand %d               \n", nId);
+	std::cout <<  std::endl;
+    gestureGenerator.AddGesture(GESTURE_TO_USE, NULL);
+
+}
+void XN_CALLBACK_TYPE update_hand(xn::HandsGenerator &generator, XnUserID nID, const XnPoint3D *pPosition, XnFloat fTime, void *pCookie) {
+	haveHand = true;
+	printf("Update Hand %d               \n", nID);
+	std::cout <<  std::endl;
+	handCoords[0] = pPosition->X;
+	handCoords[1] = pPosition->Y;
+	handCoords[2] = pPosition->Z;
+}
+
+// Callback: New user was detected
+void XN_CALLBACK_TYPE new_user(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
+	printf("New User %d\n", nId);
+	std::cout <<  std::endl;
+	userGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
+
+}
+
+
+
+// Callback: An existing user was lost
+void XN_CALLBACK_TYPE lost_user(xn::UserGenerator& generator, XnUserID nId, void* pCookie) {
+	printf("Lost user %d\n", nId);
+	std::cout <<  std::endl;
+
+}
+
+
+
+// Callback: Detected a pose
+void XN_CALLBACK_TYPE pose_detected(xn::PoseDetectionCapability& capability, const XnChar* strPose, XnUserID nId, void* pCookie) {
+	printf("Pose %s detected for user %d\n", strPose, nId);
+	std::cout <<  std::endl;
+	userGenerator.GetPoseDetectionCap().StopPoseDetection(nId);
+	userGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
+}
+
+
+
+// Callback: Started calibration
+void XN_CALLBACK_TYPE calibration_started(xn::SkeletonCapability& capability, XnUserID nId, void* pCookie) {
+	printf("Calibration started for user %d\n", nId);
+	std::cout <<  std::endl;
+}
+
+
+
+// Callback: Finished calibration
+void XN_CALLBACK_TYPE calibration_ended(xn::SkeletonCapability& capability, XnUserID nId, XnBool bSuccess, void* pCookie) {
+	if (bSuccess) {
+		printf("Calibration complete, start tracking user %d\n", nId);
+		std::cout <<  std::endl;
+		userGenerator.GetSkeletonCap().StartTracking(nId);
+
+	}
+	else {
+		printf("Calibration failed for user %d\n", nId);
+		userGenerator.GetSkeletonCap().RequestCalibration(nId, TRUE);
+	}
+}
+
+int jointPos(XnUserID player, XnSkeletonJoint eJoint) {
+    //  printf("jointpos for  user %d\n", player);
+
+	XnSkeletonJointTransformation jointTrans;
+
+	userGenerator.GetSkeletonCap().GetSkeletonJoint(player, eJoint, jointTrans);
+
+	posConfidence = jointTrans.position.fConfidence;
+
+	//userID = player;
+
+	if (filterLowConfidence && posConfidence < 0.5) {
+		return 0;
+	}
+
+	if (!raw)
+	{
+	  jointCoords[0] = off_x + (mult_x * (1280 - jointTrans.position.position.X) / 2560); //Normalize coords to 0..1 interval
+	  jointCoords[1] = off_y + (mult_y * (960 - jointTrans.position.position.Y) / 1920); //Normalize coords to 0..1 interval
+	  jointCoords[2] = off_z + (mult_z * jointTrans.position.position.Z * 7.8125 / 10000); //Normalize coords to 0..7.8125 interval
+	}
+	else if (realworld)
+	{
+		XnPoint3D realwordPoint;
+		realwordPoint.X = 0; realwordPoint.Y = 0; realwordPoint.Z = 0;
+		depth.ConvertProjectiveToRealWorld(1, &jointTrans.position.position, &realwordPoint); 
+	  
+	    jointCoords[0] = realwordPoint.X;
+	    jointCoords[1] = realwordPoint.Y;
+	    jointCoords[2] = realwordPoint.Z;
+		
+	/*	if (debugCSV) {
+			sprintf(outputFileStr, "OSC_Joint,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", eJoint, realwordPoint.X, realwordPoint.Y, realwordPoint.Z,
+				jointTrans.orientation.orientation.elements[0],
+				jointTrans.orientation.orientation.elements[1],
+				jointTrans.orientation.orientation.elements[2],
+				jointTrans.orientation.orientation.elements[3],
+				jointTrans.orientation.orientation.elements[4],
+				jointTrans.orientation.orientation.elements[5],
+				jointTrans.orientation.orientation.elements[6],
+				jointTrans.orientation.orientation.elements[7],
+				jointTrans.orientation.orientation.elements[8],
+				0.0f);
+		}
+		if (debugFacts) {
+			sprintf(outputFileStr, "(OSC_Joint (joint %d) (x %f) (y %f) (z %f) (ox1 %f) (ox2 (%f) (ox3 %f) (oy1 %f) (oy2 (%f) (oy3 %f) (oz1 %f) (oz2 (%f) (oz3 %f) (on %f))\n",
+				eJoint, realwordPoint.X, realwordPoint.Y, realwordPoint.Z,
+				jointTrans.orientation.orientation.elements[0],
+				jointTrans.orientation.orientation.elements[1],
+				jointTrans.orientation.orientation.elements[2],
+				jointTrans.orientation.orientation.elements[3],
+				jointTrans.orientation.orientation.elements[4],
+				jointTrans.orientation.orientation.elements[5],
+				jointTrans.orientation.orientation.elements[6],
+				jointTrans.orientation.orientation.elements[7],
+				jointTrans.orientation.orientation.elements[8],
+				0.0f);
+		}
+		if (debugCSV || debugFacts) {
+			if (!outputFileOpen) {
+				outputFile.open("outputFile.txt");
+				outputFileOpen = true;
+				if (debugCSV) {
+					outputFile << "OSC_Joint,joint,x,y,z,ox1,ox2,ox3,oy1,oy2,oy3,oz1,oz2,oz3,on\n";
+				}
+			}
+			outputFile << outputFileStr;
+		}*/
+	}
+	else
+	{
+	  
+	  jointCoords[0] = jointTrans.position.position.X;
+	  jointCoords[1] = jointTrans.position.position.Y;
+	  jointCoords[2] = jointTrans.position.position.Z;
+	}
+
+	if (sendOrient)
+	{
+	  orientConfidence = jointTrans.orientation.fConfidence;
+
+	  for (int i=0; i<9; i++)
+	  {
+	    jointOrients[i] = jointTrans.orientation.orientation.elements[i];
+	  }
+	}
+	
+	allJointCoords[eJoint-1][0] = jointCoords[0];
+	allJointCoords[eJoint-1][1] = jointCoords[1];
+	allJointCoords[eJoint-1][2] = jointCoords[2];
+	
+	//visualize_current_data();
+
+	return 0;
+}
+/*
+void sendOSC() {
+	if (handMode) {
+		sendHandOSC();
+		return;
+	}
+	XnUserID aUsers[15];
+	XnUInt16 nUsers = 15;
+	userGenerator.GetUsers(aUsers, nUsers);
+	for (int i = 0; i < nUsers; ++i) {
+		if (userGenerator.GetSkeletonCap().IsTracking(aUsers[i])) {
+			lo_bundle bundle = lo_bundle_new(LO_TT_IMMEDIATE);
+
+			if (jointPos(aUsers[i], XN_SKEL_HEAD) == 0) {
+				oscFunc(&bundle, "head");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_NECK) == 0) {
+				oscFunc(&bundle, "neck");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_COLLAR) == 0) {
+				oscFunc(&bundle, "l_collar");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_SHOULDER) == 0) {
+				oscFunc(&bundle, "l_shoulder");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_ELBOW) == 0) {
+				oscFunc(&bundle, "l_elbow");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_WRIST) == 0) {
+				oscFunc(&bundle, "l_wrist");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_HAND) == 0) {
+				oscFunc(&bundle, "l_hand");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_FINGERTIP) == 0) {
+				oscFunc(&bundle, "l_fingertip");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_COLLAR) == 0) {
+				oscFunc(&bundle, "r_collar");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_SHOULDER) == 0) {
+				oscFunc(&bundle, "r_shoulder");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_ELBOW) == 0) {
+				oscFunc(&bundle, "r_elbow");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_WRIST) == 0) {
+				oscFunc(&bundle, "r_wrist");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_HAND) == 0) {
+				oscFunc(&bundle, "r_hand");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_FINGERTIP) == 0) {
+				oscFunc(&bundle, "r_fingertip");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_TORSO) == 0) {
+				oscFunc(&bundle, "torso");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_WAIST) == 0) {
+				oscFunc(&bundle, "waist");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_HIP) == 0) {
+				oscFunc(&bundle, "l_hip");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_KNEE) == 0) {
+				oscFunc(&bundle, "l_knee");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_ANKLE) == 0) {
+				oscFunc(&bundle, "l_ankle");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_FOOT) == 0) {
+				oscFunc(&bundle, "l_foot");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_HIP) == 0) {
+				oscFunc(&bundle, "r_hip");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_KNEE) == 0) {
+				oscFunc(&bundle, "r_knee");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_ANKLE) == 0) {
+				oscFunc(&bundle, "r_ankle");
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_FOOT) == 0) {
+				oscFunc(&bundle, "r_foot");
+			}
+
+			lo_send_bundle(addr, bundle);
+		}
+		else {
+			//Send user's center of mass
+			sendUserPosMsg(aUsers[i]);
+		}
+	}
+}
+
+*/
+
+void get_body_positions(){
+  if (handMode) {
+		//sendHandOSC();
+		std::cout<< "hand mode not yet implemented!!!" << std::endl;
+		return;
+	}
+	XnUserID aUsers[15];
+	XnUInt16 nUsers = 15;
+	userGenerator.GetUsers(aUsers, nUsers);
+	for (int i = 0; i < nUsers; ++i) {
+		if (userGenerator.GetSkeletonCap().IsTracking(aUsers[i])) {
+		for(int j=1;j<25;j++){
+		  jointPos(aUsers[i], (XnSkeletonJoint) j);
+		}
+		/*	if (jointPos(aUsers[i], XN_SKEL_HEAD) == 0) {
+				std::cout << "got pos of head" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_NECK) == 0) {
+				std::cout << "got pos of neck" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_COLLAR) == 0) {
+				std::cout << "got pos of left collar" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_SHOULDER) == 0) {
+				std::cout << "got pos of left shoulder" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_ELBOW) == 0) {
+				std::cout << "got pos of left elbow" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_WRIST) == 0) {
+				std::cout << "got pos of left wrist" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_HAND) == 0) {
+				std::cout << "got pos of left hand" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_FINGERTIP) == 0) {
+				std::cout << "got pos of left fingertip" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_COLLAR) == 0) {
+				std::cout << "got pos of right collar" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_SHOULDER) == 0) {
+				std::cout << "got pos of right shoulder" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_ELBOW) == 0) {
+				std::cout << "got pos of right elbow" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_WRIST) == 0) {
+				std::cout << "got pos of right wrist" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_HAND) == 0) {
+				std::cout << "got pos of right hand" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_FINGERTIP) == 0) {
+				std::cout << "got pos of right fingertip" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_TORSO) == 0) {
+				std::cout << "got pos of torso" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_WAIST) == 0) {
+				std::cout << "got pos of waist" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_HIP) == 0) {
+				std::cout << "got pos of left hip" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_KNEE) == 0) {
+				std::cout << "got pos of left knee" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_ANKLE) == 0) {
+				std::cout << "got pos of left ankle" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_LEFT_FOOT) == 0) {
+				std::cout << "got pos of left_foot" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_HIP) == 0) {
+				std::cout << "got pos of right hip" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_KNEE) == 0) {
+				std::cout << "got pos of right knee" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_ANKLE) == 0) {
+				std::cout << "got pos of right ankle" << std::endl;
+			}
+			if (jointPos(aUsers[i], XN_SKEL_RIGHT_FOOT) == 0) {
+				std::cout << "got pos of right foot" << std::endl;
+			}
+*/
+		}
+		else {
+			//Send user's center of mass
+			//sendUserPosMsg(aUsers[i]);
+		}
+	}
+}
+
+/*
+
+int usage(char *name) {
+	printf("\nUsage: %s [OPTIONS]\n\
+Example: %s -a 127.0.0.1 -p 7110 -d 3 -n 1 -mx 1 -my 1 -mz 1 -ox 0 -oy 0 -oz 0\n\
+\n\
+(The above example corresponds to the defaults)\n\
+\n\
+Options:\n\
+  -a <addr>\t Address to send OSC packets to (default: localhost).\n\
+  -p <port>\t Port to send OSC packets to (default: 7110).\n\
+  -w\t\t Activate depth view window.\n\
+  -mx <n>\t Multiplier for X coordinates.\n\
+  -my <n>\t Multiplier for Y coordinates.\n\
+  -mz <n>\t Multiplier for Z coordinates.\n\
+  -ox <n>\t Offset to add to X coordinates.\n\
+  -oy <n>\t Offset to add to Y coordinates.\n\
+  -oz <n>\t Offset to add to Z coordinates.\n\
+  -r\t\t Reverse image (disable mirror mode).\n\
+  -f\t\t Activate noise filter to reduce jerkyness.\n\
+  -k\t\t Enable \"Kitchen\" mode (Animata compatibility mode).\n\
+  -n\t\t Enable hand tracking mode\n\
+  -q\t\t Enable Quartz Composer OSC format.\n\
+  -s <file>\t Save to file (only .oni supported at the moment).\n\
+  -i <file>\t Play from file (only .oni supported at the moment).\n\
+  -xr\t\tOutput raw kinect data\n\
+  -xt\t\tOutput joint orientation data\n\
+  -xd\t\tTurn on puppet defaults: -xr -xt -q -w -r\n\
+  -h\t\t Show help.\n\n\
+For a more detailed explanation of options consult the README file.\n\n",
+		   name, name);
+	exit(1);
+}
+
+*/
+
+void checkRetVal(XnStatus nRetVal) {
+	if (nRetVal != XN_STATUS_OK) {
+		printf("There was a problem initializing kinect... Make sure you have \
+connected both usb and power cables and that the driver and OpenNI framework \
+are correctly installed.\n\n");
+		exit(1);
+	}
+}
+
+
+
+
+IplImage *img = cvCreateImage(cvSize(500, 500), IPL_DEPTH_8U, 3);
+
+void terminate(int ignored) {
+	context.Shutdown();
+	cvReleaseImage(&img);
+	cvDestroyWindow("image");
+	std::cout << "bye" << std::endl;
+	exit(0);
+}
+
+
+
+
+void main_loop() {
+	// Read next available data
+	context.WaitAnyUpdateAll();
+	// Process the data
+	depth.GetMetaData(depthMD);
+	
+	get_body_positions();
+	//visualize_data();
+	//cvShowImage("image", img);
+	
+}
+
+
+
+void init_window(){
+    
+    
+    /* display the image */
+    cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
+    
+}
+
+void visualize_current_data(){
+     // cvSet(img, CV_RGB(0, 0, 0));
+
+    /* draw a green line */
+  //  cvLine(img,                         /* the dest image */
+  //         cvPoint(10, 10),             /* start point */
+  //         cvPoint(150, 80),            /* end point */
+  //         cvScalar(0, 255, 0, 0),      /* the color; green */
+  //         1, 8, 0);                    /* thickness, line type, shift */
+   
+    /* draw a blue box */
+//    cvRectangle(img,                    /* the dest image */
+//                cvPoint(20, 15),        /* top left point */
+//                cvPoint(100, 70),       /* bottom right point */
+//                cvScalar(255, 0, 0, 0), /* the color; blue */
+//                1, 8, 0);               /* thickness, line type, shift */
+   
+    /* draw a red circle */
+    cvCircle(img,                       /* the dest image */
+             cvPoint(jointCoords[0]*500, jointCoords[1]*500), 20,      /* center point and radius */
+             cvScalar(0, 0, 255, 0),    /* the color; red */
+             3, 8, 0);       
+    std::cout << "visualize: " << (jointCoords[0]*500 )<<  (jointCoords[1]*500) << std::endl;
+ 
+}
+
+
+void connect_joints(int joint1, int joint2){
+   cvLine(img,                         /* the dest image */
+           cvPoint(allJointCoords[joint1-1][0]*500, allJointCoords[joint1-1][1]*500),             /* start point */
+           cvPoint(allJointCoords[joint2-1][0]*500, allJointCoords[joint2-1][1]*500),            /* end point */
+           cvScalar(0, 255, 0, 0),      /* the color; green */
+           3, 8, 0);                    /* thickness, line type, shift */
+}
+void draw_joint(int joint, int radius=10){
+  cvCircle(img,                       /* the dest image */
+             cvPoint(allJointCoords[joint-1][0]*500, allJointCoords[joint-1][1]*500), radius,      /* center point and radius */
+             cvScalar(0, 0, 255, 0),    /* the color; red */
+             3, 8, 0);     
+}
+
+
+void visualize_all_data(){
+  connect_joints(XN_SKEL_HEAD,XN_SKEL_NECK);
+  connect_joints(XN_SKEL_NECK,XN_SKEL_TORSO);
+  connect_joints(XN_SKEL_TORSO,XN_SKEL_WAIST);
+  
+  
+  /*connect_joints(XN_SKEL_NECK, XN_SKEL_LEFT_COLLAR);
+  connect_joints(XN_SKEL_LEFT_COLLAR,XN_SKEL_LEFT_SHOULDER);*/
+  connect_joints(XN_SKEL_NECK, XN_SKEL_LEFT_SHOULDER);
+  connect_joints(XN_SKEL_LEFT_SHOULDER,XN_SKEL_LEFT_ELBOW);
+  connect_joints(XN_SKEL_LEFT_ELBOW,XN_SKEL_LEFT_WRIST);
+  connect_joints(XN_SKEL_LEFT_WRIST,XN_SKEL_LEFT_HAND);
+  connect_joints(XN_SKEL_LEFT_HAND,XN_SKEL_LEFT_FINGERTIP);
+  
+ /* connect_joints(XN_SKEL_NECK, XN_SKEL_RIGHT_COLLAR);*/
+ /* connect_joints(XN_SKEL_RIGHT_COLLAR,XN_SKEL_RIGHT_SHOULDER);*/
+ connect_joints(XN_SKEL_NECK, XN_SKEL_RIGHT_SHOULDER);
+  connect_joints(XN_SKEL_RIGHT_SHOULDER,XN_SKEL_RIGHT_ELBOW);
+  connect_joints(XN_SKEL_RIGHT_ELBOW,XN_SKEL_RIGHT_WRIST);
+  connect_joints(XN_SKEL_RIGHT_WRIST,XN_SKEL_RIGHT_HAND);
+  connect_joints(XN_SKEL_RIGHT_HAND,XN_SKEL_RIGHT_FINGERTIP);
+  
+  
+  connect_joints(XN_SKEL_TORSO,XN_SKEL_LEFT_HIP);
+  connect_joints(XN_SKEL_LEFT_HIP,XN_SKEL_LEFT_KNEE);
+  connect_joints(XN_SKEL_LEFT_KNEE,XN_SKEL_LEFT_ANKLE);
+  connect_joints(XN_SKEL_LEFT_ANKLE,XN_SKEL_LEFT_FOOT);
+  
+  connect_joints(XN_SKEL_TORSO,XN_SKEL_RIGHT_HIP);
+  connect_joints(XN_SKEL_RIGHT_HIP,XN_SKEL_RIGHT_KNEE);
+  connect_joints(XN_SKEL_RIGHT_KNEE,XN_SKEL_RIGHT_ANKLE);
+  connect_joints(XN_SKEL_RIGHT_ANKLE,XN_SKEL_RIGHT_FOOT);
+  
+  draw_joint(XN_SKEL_HEAD, 30);
+  draw_joint(XN_SKEL_LEFT_HAND);
+  draw_joint(XN_SKEL_RIGHT_HAND);
+  draw_joint(XN_SKEL_LEFT_FOOT);
+  draw_joint(XN_SKEL_RIGHT_FOOT);
+  
+  draw_joint(XN_SKEL_LEFT_COLLAR, 5);
+  draw_joint(XN_SKEL_RIGHT_COLLAR, 5);
+}
+
+
+
+
+
+int main(int argc, char **argv) {
+	printf("Initializing...\n");
+	unsigned int arg = 1,
+				 require_argument = 0,
+				 port_argument = 0;
+	XnMapOutputMode mapMode;
+	XnStatus nRetVal = XN_STATUS_OK;
+	XnCallbackHandle hUserCallbacks, hCalibrationCallbacks, hPoseCallbacks, hHandsCallbacks, hGestureCallbacks;
+	xn::Recorder recorder;
+
+	context.Init();
+
+	
+
+	depth.Create(context);
+
+	if (!play) {
+		mapMode.nXRes = XN_VGA_X_RES;
+		mapMode.nYRes = XN_VGA_Y_RES;
+		mapMode.nFPS = 30;
+		depth.SetMapOutputMode(mapMode);
+	}
+
+	if (handMode) {
+	  std::cout<<"using hand mode\n"<<std::endl;
+		nRetVal = handsGenerator.Create(context);
+		nRetVal = gestureGenerator.Create(context);
+		nRetVal = gestureGenerator.RegisterGestureCallbacks(Gesture_Recognized, Gesture_Process, NULL, hGestureCallbacks);
+		nRetVal = handsGenerator.RegisterHandCallbacks(new_hand, update_hand, lost_hand, NULL, hHandsCallbacks);
+		if (filter)
+			handsGenerator.SetSmoothing(0.2);
+	}
+	else {
+	  std::cout<<"using no hand mode\n"<<std::endl;
+		nRetVal = context.FindExistingNode(XN_NODE_TYPE_USER, userGenerator);
+		if (nRetVal != XN_STATUS_OK)
+			nRetVal = userGenerator.Create(context);
+
+		checkRetVal(userGenerator.RegisterUserCallbacks(new_user, lost_user, NULL, hUserCallbacks));
+		checkRetVal(userGenerator.GetSkeletonCap().RegisterCalibrationCallbacks(calibration_started, calibration_ended, NULL, hCalibrationCallbacks));
+		checkRetVal(userGenerator.GetPoseDetectionCap().RegisterToPoseCallbacks(pose_detected, NULL, NULL, hPoseCallbacks));
+		checkRetVal(userGenerator.GetSkeletonCap().GetCalibrationPose(g_strPose));
+		checkRetVal(userGenerator.GetSkeletonCap().SetSkeletonProfile(XN_SKEL_PROFILE_ALL));
+		if (filter)
+			userGenerator.GetSkeletonCap().SetSmoothing(0.8);
+	}
+
+	xnSetMirror(depth, !mirrorMode);
+
+	
+	signal(SIGTERM, terminate);
+	signal(SIGINT, terminate);
+	
+	
+	struct sigaction sa;
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = &terminate;
+	sigaction(SIGINT, &sa,NULL);
+
+	
+
+	
+	printf("Initialized Kinect, looking for users...\n\n");
+	context.StartGeneratingAll();
+
+	if (handMode) {
+		nRetVal = gestureGenerator.AddGesture(GESTURE_TO_USE, NULL);
+	}
+	
+	cvNamedWindow("window1");
+	//init_window();
+	
+	/*cvShowImage("window1", img);
+	cvSet(img, CV_RGB(0, 0, 0));
+	cvCircle(img,                       
+		      cvPoint(150, 370), 50,     
+		      cvScalar(0, 0, 255, 0),   
+		      10, 8, 0);   
+	cvShowImage("window1", img);
+	cvWaitKey(0);*/
+
+
+	while(true){
+		cvSet(img, CV_RGB(0, 0, 0));
+		
+		
+		
+		main_loop();
+		
+		visualize_all_data();
+
+		cvShowImage("window1", img);
+		int k = cvWaitKey(1);
+		
+		if (k != 0){
+		  std::cout<<"got key: " << k <<std::endl;
+		}
+		
+		//std::cout<<"show image\n"<<std::endl;
+	}
+	
+
+	terminate(0);
+}
+