Scale the skeleton with processing

815 views Asked by At

Well I’m making a sketch that uses the SimpleOpenNI library in Processing, and I’m mounting a 3D design over the skeleton, but I have been thinking that if a different person stands in front of the Kinect the model will be different if the person is taller or smaller than me, since I’m doing the tests, and I want to know if there’s a way to scale the skeleton made by the SimpleOpenNI, so I can make that the standard in my sketch so anyone that stands in front will be the same height in the sketch and all the parts of the 3D will remain in the same place. I hope you guys can give me a hint since this is my first project using the skeleton. Thanks!

1

There are 1 answers

3
George Profenza On BEST ANSWER

If you want to draw the 3D skeleton at the same scale you can create a 3D scene with a representation of the skeleton in a fixed position with a fixed camera (that way the scale won't change) and simply use the joint's orientation (rotation matrices)(not the positions) to update your custom avatar/character representation.

You get the orientation as a PMatrix3D using SimpleOpenNI's getJointOrientationSkeleton() method. You can then use Processing's applyMatrix() to orient your custom mesh:

PMatrix3D  orientation = new PMatrix3D();
context.getJointOrientationSkeleton(userId,SimpleOpenNI.SKEL_HEAD,orientation);
pushMatrix();
applyMatrix(orientation);//rotate box based on head orientation
box(40);
popMatrix();  

or as a minimal sample:

import SimpleOpenNI.*;
SimpleOpenNI  context;
PMatrix3D  orientation = new PMatrix3D();//create a new matrix to store the steadiest orientation (used in rendering)
PMatrix3D  newOrientaton = new PMatrix3D();//create a new matrix to store the newest rotations/orientation (used in getting data from the sensor)
void setup() {
  size(640, 480,P3D);
  context = new SimpleOpenNI(this);
  context.enableUser();//enable skeleton tracking
}
void draw(){
  context.update(); 
  background(0);
  lights();
  translate(width * .5, height * .5,0);
  if(context.isTrackingSkeleton(1)){//we're tracking user #1
        newOrientaton.reset();//reset the raw sensor orientation 
        float confidence = context.getJointOrientationSkeleton(userId,SimpleOpenNI.SKEL_HEAD,newOrientaton);//retrieve the head orientation from OpenNI
        if(confidence > 0.001){//if the new orientation is steady enough (and play with the 0.001 value to see what works best)
          orientation.reset();//reset the matrix and get the new values
          orientation.apply(newOrientaton);//copy the steady orientation to the matrix we use to render the avatar
        }
        //draw a box using the head's orientation
        pushMatrix();
        applyMatrix(orientation);//rotate box based on head orientation
        box(40);
        popMatrix();  
  }
}

It will be up to you to organize the hierarchy of the character and setup a camera with the desired perspective.