/* -------------------------------------------------------------------------- * SimpleOpenNI User3d 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: 02/16/2011 (m/d/y) * ---------------------------------------------------------------------------- * this demos is at the moment only for 1 user, will be implemented later * ---------------------------------------------------------------------------- */ import SimpleOpenNI.*; SimpleOpenNI context; float zoomF =0.5f; float rotX = radians(180); // by default rotate the whole scene 180deg around the x-axis, // the data from openni comes upside down float rotY = radians(0); boolean autoCalib=true; PVector bodyCenter = new PVector(); PVector bodyDir = new PVector(); PImage bodyTextures[] = new PImage[11]; static final int HEAD_NECK=0; static final int LEFT_SHOULDER_LEFT_ELBOW=1; static final int LEFT_ELBOW_LEFT_HAND=2; static final int LEFT_HIP_LEFT_KNEE=3; static final int LEFT_KNEE_LEFT_FOOT=4; static final int RIGHT_SHOULDER_RIGHT_ELBOW=5; static final int RIGHT_ELBOW_RIGHT_HAND=6; static final int RIGHT_HIP_RIGHT_KNEE=7; static final int RIGHT_KNEE_RIGHT_FOOT=8; static final int SHOULDERS_HIPS=9; static final int LEFT_HIP_RIGHT_HIP=10; void setup() { size(1024, 768, P3D); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem context = new SimpleOpenNI(this); println(SimpleOpenNI.SKEL_HEAD); // disable mirror context.setMirror(false); // 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); stroke(255, 255, 255); smooth(); perspective(radians(45), float(width)/float(height), 10, 150000); noCursor(); loadBodyTextures(); } void loadBodyTextures() { String basepath = "/Users/rtwomey/Pictures/kpuppet/rauschenberg_"; bodyTextures[HEAD_NECK]=loadImage(basepath+"HEAD_NECK.jpg"); bodyTextures[LEFT_SHOULDER_LEFT_ELBOW]=loadImage(basepath+"LEFT_SHOULDER_LEFT_ELBOW.jpg"); bodyTextures[LEFT_ELBOW_LEFT_HAND]=loadImage(basepath+"LEFT_ELBOW_LEFT_HAND.jpg"); bodyTextures[LEFT_HIP_LEFT_KNEE]=loadImage(basepath+"LEFT_HIP_LEFT_KNEE.jpg"); bodyTextures[LEFT_KNEE_LEFT_FOOT]=loadImage(basepath+"LEFT_KNEE_LEFT_FOOT.jpg"); bodyTextures[RIGHT_SHOULDER_RIGHT_ELBOW]=loadImage(basepath+"RIGHT_SHOULDER_RIGHT_ELBOW.jpg"); bodyTextures[RIGHT_ELBOW_RIGHT_HAND]=loadImage(basepath+"RIGHT_ELBOW_RIGHT_HAND.jpg"); bodyTextures[RIGHT_HIP_RIGHT_KNEE]=loadImage(basepath+"RIGHT_HIP_RIGHT_KNEE.jpg"); bodyTextures[RIGHT_KNEE_RIGHT_FOOT]=loadImage(basepath+"RIGHT_KNEE_RIGHT_FOOT.jpg"); bodyTextures[SHOULDERS_HIPS]=loadImage(basepath+"SHOULDERS_HIPS.jpg"); bodyTextures[LEFT_HIP_RIGHT_HIP]=loadImage(basepath+"LEFT_HIP_RIGHT_HIP.jpg"); println("done loading images."); } void draw() { // update the cam context.update(); background(0, 0, 0); // set the scene pos translate(width/2, height/2, 0); rotateX(rotX); rotateY(rotY); scale(zoomF); int[] depthMap = context.depthMap(); int steps = 3; // to speed up the drawing, draw every third point int index; PVector realWorldPoint; translate(0, 0, -1000); // set the rotation center of the scene 1000 infront of the camera // stroke(100); // for(int y=0;y < context.depthHeight();y+=steps) // { // for(int x=0;x < context.depthWidth();x+=steps) // { // index = x + y * context.depthWidth(); // if(depthMap[index] > 0) // { // // draw the projected point // realWorldPoint = context.depthMapRealWorld()[index]; // point(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z); // } // } // } // draw the skeleton if it's available int[] userList = context.getUsers(); for (int i=0;i