Skip to content

Commit

Permalink
Hand distance MTS
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshredcobra committed Nov 1, 2012
1 parent 705766b commit f1d2f1e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions kinect_codes/chSK_ex03_joint_distance/chSK_ex03_joint_distance.pde
@@ -0,0 +1,71 @@
import SimpleOpenNI.*;
SimpleOpenNI kinect;

void setup() {
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);

size(640, 480);
stroke(255,0,0);
strokeWeight(5);
}

void draw() {
kinect.update();
image(kinect.depthImage(), 0, 0);

IntVector userList = new IntVector();
kinect.getUsers(userList);

if (userList.size() > 0) {
int userId = userList.get(0);

if ( kinect.isTrackingSkeleton(userId)) {
PVector leftHand = new PVector();
PVector rightHand = new PVector();

kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftHand);
kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, rightHand);

// calculate difference by subtracting one vector from another
PVector differenceVector = PVector.sub(leftHand, rightHand);
// calculate the distance and direction
// of the difference vector
float magnitude = differenceVector.mag();
differenceVector.normalize();
// draw a line between the two handsst
kinect.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HAND, SimpleOpenNI.SKEL_RIGHT_HAND);
// display
pushMatrix();
scale(4);
fill(differenceVector.x * 255, differenceVector.y * 255, differenceVector.z * 255);
text("m: " + magnitude, 5, 10);
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);
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f1d2f1e

Please sign in to comment.