How can i draw a custom limb on the kinect skeleton

edited June 2015 in Kinect

Hello people of the forum,

I'm new to processing but fairly familiar with coding. For a school project, i'm making an interactive installation where the visitor is able to play with his "shadow". They should be able to draw objects like wings or capes onto his shadow. These objects then need to move along with the skeleton of the player.

For instances, if i draw a big hat on my head it needs to move along with my head.

Now i made this simple code wich makes a silhouet of the player and the player is than able to draw on it and save screenshots.

 import SimpleOpenNI.*;
    SimpleOpenNI context;
    PImage userImage;
    int[] userMap;
    PImage rgbImage;
    PGraphics pg;
    color pixelColor;
    
    int dikte = 10;
    
    void setup(){
     
      size(1024,768);
      context=new SimpleOpenNI(this);
      context.enableRGB();
      context.enableDepth();
      context.enableUser(); 
      pg = createGraphics(1024,768);
      background(255);
     
      userImage=createImage(640,480,RGB);
    }
    void draw(){
     
      pg.beginDraw();
      pg.strokeWeight(dikte);
      if (mousePressed && (mouseButton == LEFT) == true) {
        pg.stroke(0);
        pg.line(mouseX, mouseY, pmouseX, pmouseY);
      }
      
      if (mousePressed && (mouseButton == RIGHT) == true) {
        pg.stroke(255);
        pg.line(mouseX, mouseY, pmouseX, pmouseY);
      }
      
      context.update();
      rgbImage=context.rgbImage();
     
      userMap=context.userMap();
      for(int y=0;y2) {
            //adjust the stroke weight
            dikte--;
        }
        
        
      }
    }

Now i have tested and inspected these codes, but i'm not able to change it so that the skeletons uses the draw function to use that as the limb.

void draw(){
  //clears the screen with the black color, this is usually a good idea 
  //to avoid color artefacts from previous draw iterations
  background(255);
 
  //asks kinect to send new data
  context.update();
 
  //retrieves depth image
  PImage depthImage=context.depthImage();
  depthImage.loadPixels();
 
  //get user pixels - array of the same size as depthImage.pixels, that gives information about the users in the depth image:
  // if upix[i]=0, there is no user at that pixel position
  // if upix[i] > 0, upix[i] indicates which userid is at that position
  int[] upix=context.userMap();
 
  //colorize users
  for(int i=0; i < upix.length; i++){
    if(upix[i] > 0){
      //there is a user on that position
      //NOTE: if you need to distinguish between users, check the value of the upix[i]
      img.pixels[i]=color(0,0,255);
    }else{
      //add depth data to the image
     img.pixels[i]=depthImage.pixels[i];
    }
  }
  img.updatePixels();
 
  //draws the depth map data as an image to the screen 
  //at position 0(left),0(top) corner
  image(img,0,0);
 
  //draw significant points of users
 
  //get array of IDs of all users present 
  int[] users=context.getUsers();
 
  ellipseMode(CENTER);
 
    //iterate through users
    for(int i=0; i < users.length; i++){
    int uid=users[i];
    
    //draw center of mass of the user (simple mean across position of all user pixels that corresponds to the given user)
    PVector realCoM=new PVector();
    
    //get the CoM in realworld (3D) coordinates
    context.getCoM(uid,realCoM);
    PVector projCoM=new PVector();
    
    //convert realworld coordinates to projective (those that we can use to draw to our canvas)
    context.convertRealWorldToProjective(realCoM, projCoM);
    fill(255,0,0);
    ellipse(projCoM.x,projCoM.y,10,10);
 
    //check if user has a skeleton
    if(context.isTrackingSkeleton(uid)){
      //draw head
      PVector realHead=new PVector();
      
      //get realworld coordinates of the given joint of the user (in this case Head -> SimpleOpenNI.SKEL_HEAD)
          context.getJointPositionSkeleton(uid,SimpleOpenNI.SKEL_HEAD,realHead);
      PVector projHead=new PVector();
      context.convertRealWorldToProjective(realHead, projHead);
      fill(0,255,0);
      ellipse(projHead.x,projHead.y,10,10);
 
      //draw left hand
      PVector realLHand=new PVector();
      context.getJointPositionSkeleton(uid,SimpleOpenNI.SKEL_LEFT_HAND,realLHand);
      PVector projLHand=new PVector();
      context.convertRealWorldToProjective(realLHand, projLHand);
      fill(255,255,0);
      ellipse(projLHand.x,projLHand.y,10,10);
 
    }
  }
 
}

Can someone please help me out with this,

kind regards

Answers

Sign In or Register to comment.