/* -------------------------------------------------------------------------- * SimpleOpenNI User Load + Save Calibration Test * -------------------------------------------------------------------------- * Processing Wrapper for the OpenNI/Kinect library * http://code.google.com/p/simple-openni * -------------------------------------------------------------------------- * prog: Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/ * date: 06/11/2011 (m/d/y) * ---------------------------------------------------------------------------- */ import SimpleOpenNI.*; SimpleOpenNI context; void setup() { context = new SimpleOpenNI(this); // enable depthMap generation if(context.enableDepth() == false) { println("Can't open the depthMap, maybe the camera is not connected!"); exit(); return; } // enable skeleton generation for all joints context.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL); background(200,0,0); stroke(0,0,255); strokeWeight(3); smooth(); size(context.depthWidth(), context.depthHeight()); } void draw() { // update the cam context.update(); // draw depthImageMap image(context.depthImage(),0,0); // draw the skeleton if it's available if(context.isTrackingSkeleton(1)) drawSkeleton(1); } // draw the skeleton with the selected joints void drawSkeleton(int userId) { // to get the 3d joint data /* PVector jointPos = new PVector(); context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_NECK,jointPos); println(jointPos); */ context.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK); context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER); context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW); context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND); context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER); context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW); context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND); context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO); context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO); context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP); context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE); context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT); context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP); context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE); context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT); } // ----------------------------------------------------------------- // Processing events void keyPressed() { // check for active users IntVector userList = new IntVector(); context.getUsers(userList); if(userList.size() < 1) { println("You need at least one active user!"); return; } int user = userList.get(0); switch(key) { case 's': if(context.isTrackingSkeleton(user)) { if(context.saveCalibrationDataSkeleton(user,"calibration.skel")) println("Saved current calibration to file."); else println("Can't save current calibration to file."); } else println("There is no calibration data to save."); break; case 'l': /* // discrete way with the original OpenNI classes UserGenerator userGenerator = context.getUserGenerator(); // setup path String path = dataPath("calibration.skel"); println(path); if(userGenerator.GetSkeletonCap().LoadCalibrationDataFromFile(user,path) == SimpleOpenNI.XN_STATUS_OK) { context.startTrackingSkeleton(user); println("Load calibration from file."); } else println("Can't load calibration file."); */ if(context.loadCalibrationDataSkeleton(user,"calibration.skel")) { context.startTrackingSkeleton(user); println("Load calibration from file."); } else println("Can't load calibration file."); break; } } // ----------------------------------------------------------------- // SimpleOpenNI events void onNewUser(int userId) { println("onNewUser - userId: " + userId); if(context.isTrackingSkeleton(1)) return; println(" start pose detection"); context.startPoseDetection("Psi",userId); } void onLostUser(int userId) { println("onLostUser - userId: " + userId); } void onStartCalibration(int userId) { println("onStartCalibration - userId: " + userId); } void onEndCalibration(int userId, boolean successfull) { println("onEndCalibration - userId: " + userId + ", successfull: " + successfull); if (successfull) { println(" User calibrated !!!"); context.startTrackingSkeleton(userId); } else { println(" Failed to calibrate user !!!"); println(" Start pose detection"); context.startPoseDetection("Psi",userId); } } void onStartPose(String pose,int userId) { println("onStartPose - userId: " + userId + ", pose: " + pose); println(" stop pose detection"); context.stopPoseDetection(userId); context.requestCalibrationSkeleton(userId, true); } void onEndPose(String pose,int userId) { println("onEndPose - userId: " + userId + ", pose: " + pose); }