Skip to content

Instantly share code, notes, and snippets.

@bnferguson
Created July 21, 2012 15:52
Show Gist options
  • Save bnferguson/3156218 to your computer and use it in GitHub Desktop.
Save bnferguson/3156218 to your computer and use it in GitHub Desktop.
import processing.opengl.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
void setup() {
size(1028, 768, OPENGL);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
kinect.setMirror(true);
fill(255, 0, 0);
}
void draw() {
kinect.update();
background(255);
translate(width/2, height/2, 0);
rotateX(radians(180));
IntVector userList = new IntVector();
kinect.getUsers(userList);
if (userList.size() > 0) {
int userId = userList.get(0);
if ( kinect.isTrackingSkeleton(userId)) {
PVector position = new PVector();
kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_TORSO, position);
PMatrix3D orientation = new PMatrix3D();
float confidence = kinect.getJointOrientationSkeleton(userId, SimpleOpenNI.SKEL_TORSO, orientation);
println(confidence);
drawJoint(userId, SimpleOpenNI.SKEL_HEAD);
drawJoint(userId, SimpleOpenNI.SKEL_RIGHT_HAND);
drawJoint(userId, SimpleOpenNI.SKEL_LEFT_HAND);
pushMatrix();
// move to the position of the TORSO
translate(position.x, position.y, position.z);
// adopt the TORSO's orientation
// to be our coordinate system
applyMatrix(orientation);
// draw x-axis in red
stroke(255, 0, 0);
strokeWeight(3);
line(0, 0, 0, 150, 0, 0);
// draw y-axis in blue
stroke(0, 255, 0);
line(0, 0, 0, 0, 150, 0);
// draw z-axis in green
stroke(0, 0, 255);
line(0, 0, 0, 0, 0, 150);
popMatrix();
}
}
}
void drawJoint(int userId, int jointType1) {
PVector jointPos1 = new PVector();
float confidence;
confidence = kinect.getJointPositionSkeleton(userId,jointType1, jointPos1);
println(confidence);
if (confidence > 0.8) {
pushMatrix();
translate(jointPos1.x,jointPos1.y,jointPos1.z);
box(20, 20, 20);
popMatrix();
}
}
// user-tracking callbacks!
void onNewUser(int userId) {
println("start pose detection");
kinect.startPoseDetection("Psi", userId);
}
void onEndCalibration(int userId, boolean successful) {
if (successful) {
println(" User calibrated !!!");
kinect.startTrackingSkeleton(userId);
}
else {
println(" Failed to calibrate user !!!");
kinect.startPoseDetection("Psi", userId);
}
}
void onStartPose(String pose, int userId) {
println("Started pose for user");
kinect.stopPoseDetection(userId);
kinect.requestCalibrationSkeleton(userId, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment