Kinect Head Tracking multiple users

edited February 2016 in Kinect

Hello,

I am using the SimpleOpenNI library to track users in the room and let eyes follow the users movement.

Here is my code so far:

import SimpleOpenNI.*;

SimpleOpenNI context;

int Pupilh = 200;
int Pupilw = 150;
int Eyeh   = 500;
int Eyew   = 350;

int EyeDistance = 400;

int Sizew  = 1250;
int Sizeh  = 800;
int fps    = 30;

int ColBlack = 0;
int ColWhite = 255;

int DefaultX = 0;
int DefaultY = 0;
boolean lBodyAppeared = false; 
int user = 0;


void setup() { 
  size( Sizew, Sizeh );
  background( ColBlack );
  
  context = new SimpleOpenNI(this);
  
  if(!context.enableDepth( Sizew, Sizeh, fps )) {
     println("Kamera ist nicht angeschlossen."); 
     exit();
     return;
  }
  
  context.enableUser();  
  
  DefaultX = int( ( width / 2 ) - 175 );
  DefaultY = int( ( height / 2 ) );
  
  context.setMirror( false );
  
  frameRate( fps );    
  smooth();  
}


void DrawGround() {
  fill( ColWhite );
  ellipse( DefaultX, DefaultY, Eyew, Eyeh );
  ellipse( DefaultX + EyeDistance, DefaultY, Eyew, Eyeh );
  
  noFill(); 
  
  fill( ColBlack );
  ellipse( DefaultX, DefaultY, Pupilw, Pupilh );
  ellipse( DefaultX + EyeDistance, DefaultY, Pupilw, Pupilh );
}


void draw() { 
  fill( ColWhite );
  ellipse( DefaultX, DefaultY, Eyew, Eyeh );
  ellipse( DefaultX + EyeDistance, DefaultY, Eyew, Eyeh );
  
  context.update();
  context.userImage();
  PVector jointPos = new PVector();
  PVector projectivePos = new PVector();
  float  confidence;
  
  int[] userList = context.getUsers();
  
  user = 0;
  if( context.getNumberOfUsers() - 1 >= 0 ) 
    user = userList[context.getNumberOfUsers() - 1];
  else
    user = 0;
  
  if( user != 0 && context.isTrackingSkeleton( user )) {
    confidence = context.getJointPositionSkeleton( user, SimpleOpenNI.SKEL_HEAD, jointPos);
    
    if( confidence > 0.5 ) {
      context.convertRealWorldToProjective(jointPos, projectivePos);   
  
      fill( ColWhite );
      
      ellipse( DefaultX, DefaultY, Eyew, Eyeh );
      ellipse( DefaultX + EyeDistance, DefaultY, Eyew, Eyeh ); 
      
      fill( ColBlack );
      
      float fMoveFactorx = min( 1., abs( projectivePos.x/context.depthWidth() ));
      float fMoveFactory = min( abs( projectivePos.y/context.depthHeight() ));
  
      ellipse( (DefaultX - (Eyew / 2)) + (320 * fMoveFactorx), (DefaultY - 150) + (Eyeh * fMoveFactory), Pupilw, Pupilh );
      ellipse( (DefaultX + EyeDistance - (Eyew / 2)) + (320 * fMoveFactorx), (DefaultY - 150) + (Eyeh * fMoveFactory), Pupilw, Pupilh );
    }
  }
  else {
    fill( ColBlack );
    ellipse( DefaultX, DefaultY, Pupilw, Pupilh );
    ellipse( DefaultX + EyeDistance, DefaultY, Pupilw, Pupilh );
  }
} 

void onNewUser(SimpleOpenNI curContext, int userId)
{  
  curContext.startTrackingSkeleton(userId);
}

With the code I would like to track people if they walk in front of the Kinect device. My problem is that the tracking is not working every time. Only one user should be tracked and if the user is not tracked anymore another user should be tracked. But it doesn't work right. If you do slow motions and only one person is in front of the kinect everything works fine.

Can you please help me to improve the tracking? It's not that much of code and I need a solution until tomorrow. The Sketch is running on a Mac OSX oprating system and is a 1517 Model V1 Kinect device. This sketch will be shown on an Exhibition in the university. I user the Processing version 2.2.1.

Thank you in advance for helping me.

Answers

Sign In or Register to comment.