I'm working with Kinect and need some guidance for skeleton interaction

Hello everyone this is my first post so sorry if i make a mistake with the rules in general.

First i’d like to explain my code, it’s a simple code to read skeleton with Kinect and add an image to the HEAD, i’d like to make an extra bit where if two hands are close or at the same position as HEAD the image changes.

If anyone has any tips or somewhere where i can find information on how to do this it would be perfect as i want to try to do it myself.

Here is the code so far.

import SimpleOpenNI.*;

SimpleOpenNI context;
color[] userClr = new color[]{ color(255,0,0),
   color(0,255,0),
   color(0,0,255),
   color(255,255,0),
   color(255,0,255),
   color(0,255,255)};
PVector com = new PVector(); 
PVector com2d = new PVector();
PImage nani;
void setup(){
  nani = loadImage("balde.png");
   size(640,480);
    imageMode(CENTER);
   context = new SimpleOpenNI(this);
   if(context.isInit() == false){
      println("Can't init SimpleOpenNI, maybe the camera is not connected!"); 
      exit();
      return; 
   }
   // enable depthMap generation 
   context.enableDepth();
   // enable skeleton generation for all joints
   context.enableUser();
   context.enableRGB();
   background(200,0,0);
   stroke(0,0,255);
   strokeWeight(3);
   smooth(); 
}

void draw(){
   // update the cam
   context.update();
   // draw depthImageMap
   //image(context.depthImage(),0,0);
   image(context.rgbImage(),320,240);
   // draw the skeleton if it's available
   int[] userList = context.getUsers();
   for(int i=0;i<userList.length;i++){
      if(context.isTrackingSkeleton(userList[i])){
         stroke(userClr[ (userList[i] - 1) % userClr.length ] );
         drawSkeleton(userList[i]);
      } 
   } 
}

// draw the skeleton with the selected joints
void drawSkeleton(int userId){
   // define wich part it tracks
   PVector jointPos = new PVector();
   context.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,jointPos);
     PVector convertedHead = new PVector();
   context.convertRealWorldToProjective(jointPos,convertedHead);
   //desenhar uma elipse sobre a parte do corpo rastreada
   fill(255,0,0);
   image(nani,convertedHead.x,convertedHead.y);


/*
context.drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);

context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_LEFT_SHOULDER);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW, SimpleOpenNI.SKEL_LEFT_HAND);

context.drawLimb(userId, SimpleOpenNI.SKEL_NECK, SimpleOpenNI.SKEL_RIGHT_SHOULDER);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_RIGHT_ELBOW);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW, SimpleOpenNI.SKEL_RIGHT_HAND);

context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);

context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_LEFT_HIP);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP, SimpleOpenNI.SKEL_LEFT_KNEE);
context.drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE, SimpleOpenNI.SKEL_LEFT_FOOT);

context.drawLimb(userId, SimpleOpenNI.SKEL_TORSO, SimpleOpenNI.SKEL_RIGHT_HIP);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP, SimpleOpenNI.SKEL_RIGHT_KNEE);
context.drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE, SimpleOpenNI.SKEL_RIGHT_FOOT); 
*/ 
}

// -----------------------------------------------------------------
// SimpleOpenNI events

void onNewUser(SimpleOpenNI curContext, int userId)
{
println("onNewUser - userId: " + userId);
println("\tstart tracking skeleton");

curContext.startTrackingSkeleton(userId);
}

void onLostUser(SimpleOpenNI curContext, int userId)
{
println("onLostUser - userId: " + userId);
}

void onVisibleUser(SimpleOpenNI curContext, int userId)
{
//println("onVisibleUser - userId: " + userId);
}
void keyPressed()
{
switch(key)
{
case ' ':
context.setMirror(!context.mirror());
break;
}
}
1 Like

I would start with a search like this. Notice I am focusing on keywords from your topic. You will get some hints. Unfortunately most of the links are few years old but they could potentially give you an insight of what you could do. Have a look at the code and see their approach. If you find a code that you find interesting or related to your application and you need clarification, post here with relevant information (code snippets, links, docs, etc) and I am sure people could help.

Kf

1 Like