/* -------------------------------------------------------------------------- * 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; PaperDoll doll; 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(); //PVector[] sc = new PVector[14]; float []sx = new float[14]; float []sy = new float[14]; int [] jointTypes = new int[14]; 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; boolean recordFlag=false; void setup() { size(1400, 800, 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; // } if(recordFlag == false) { // playing, this works without the camera if ( context.openFileRecording("test.oni") == false) { println("can't find recording !!!!"); exit(); } // it's possible to run the sceneAnalyzer over the recorded data strea if ( context.enableScene() == false) { println("can't setup scene!!!!"); exit(); return; } println("This file has " + context.framesPlayer() + " frames."); } else { 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(); doll=new PaperDoll(); doll.loadBodyTextures(); assignJointTypes(); } void assignJointTypes() { jointTypes[PaperDoll.HEAD]=SimpleOpenNI.SKEL_HEAD; jointTypes[PaperDoll.NECK]=SimpleOpenNI.SKEL_NECK; jointTypes[PaperDoll.LEFT_SHOULDER]=SimpleOpenNI.SKEL_LEFT_SHOULDER; jointTypes[PaperDoll.LEFT_ELBOW]=SimpleOpenNI.SKEL_LEFT_ELBOW; jointTypes[PaperDoll.LEFT_HAND]=SimpleOpenNI.SKEL_LEFT_HAND; jointTypes[PaperDoll.RIGHT_SHOULDER]=SimpleOpenNI.SKEL_RIGHT_SHOULDER; jointTypes[PaperDoll.RIGHT_ELBOW]=SimpleOpenNI.SKEL_RIGHT_ELBOW; jointTypes[PaperDoll.RIGHT_HAND]=SimpleOpenNI.SKEL_RIGHT_HAND; jointTypes[PaperDoll.LEFT_HIP]=SimpleOpenNI.SKEL_LEFT_HIP; jointTypes[PaperDoll.LEFT_KNEE]=SimpleOpenNI.SKEL_LEFT_KNEE; jointTypes[PaperDoll.LEFT_FOOT]=SimpleOpenNI.SKEL_LEFT_FOOT; jointTypes[PaperDoll.RIGHT_HIP]=SimpleOpenNI.SKEL_RIGHT_HIP; jointTypes[PaperDoll.RIGHT_KNEE]=SimpleOpenNI.SKEL_RIGHT_KNEE; jointTypes[PaperDoll.RIGHT_FOOT]=SimpleOpenNI.SKEL_RIGHT_FOOT; } void draw() { // update the cam context.update(); background(0, 0, 0); // set the scene pos int[] depthMap = context.depthMap(); int steps = 3; // to speed up the drawing, draw every third point int index; PVector realWorldPoint; // 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