1

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!

George Profenza
  • 50,687
  • 19
  • 144
  • 218
dzuritaa
  • 691
  • 1
  • 6
  • 13

1 Answers1

2

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.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Thanks! It really helps me. Well I wanted to ask you one more thing, is there a way that I can make that the 3d skeleton stops from being shaking? I can see the 3d parts of the skeleton in using but they are shaking all the time. I hope you can help me :) – dzuritaa Jun 02 '14 at 20:14
  • Great! Good question about the shaking. One thing you can do is check the confidence of the tracking.See the updated code above: we check this confidence and only update the rendered orientation if the tracked orientation is steady enough. There used to be a method allowing you to set tracking smoothing/easing per joints. That's no longer the case, but it can be done manually. Start by looking into easing/smoothing animation to get an idea. Once you can ease one value, you can do the same for all matrix elements... – George Profenza Jun 03 '14 at 01:02
  • ...Also, make sure you have decent tracking condition for the sensor: avoid (strong) sun light (or strong incandescent lights...lights easily visible in the IR spectrum) as this will have an effect on the sensors IR pattern and hence the quality of the tracking. Try to use a simple scene as a complex scene could contain elements that might trigger false positives in the tracking algorithm. HTH – George Profenza Jun 03 '14 at 01:04