Blog UniversidadNuevos Medios

Paint Kinect Processing SimpleOpenni

By septiembre 6, 2013 mayo 31st, 2020 No Comments

import SimpleOpenNI.*;
SimpleOpenNI  kinect;
color currentColor;
 int diametro=20;

void setup() {
  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL); 
  kinect.setMirror(true);

  size(1000,480);
  //background(255);
  color currentColor;
  noStroke();
  textFont(createFont(«Georgia», 24));
fill(150);
stroke(1);
noStroke();
fill(255,255,255,50);
rect(0,0,500,480);
fill(150);
rect(0,0,50,480);
fill(0,0,0,50);
rect(50,0,450,40);
// amarillo
fill(255,255,0);
rect(10,100,40,40);
// morado
fill(255,0,255);
rect(10,200,40,40);
//rojo
fill(255,0,0);
rect(10,300,40,40);
//verde
fill(0,255,0);
rect(10,400,40,40);
fill(255);
//Menos
  text(«Menos», 55, 30);
//Mas
  text(«Más», 440, 30);
//Borrar
  text(«Borrar», 255, 30);
 
 

 
}

void draw() {
  kinect.update();
    // draw depthImageMap
 
 
 
  
image(kinect.depthImage(),500,0);
//DEPTH
fill(255,255,255,50);
rect(500,0,1000,480);

fill(0,0,0,50);
rect(500,0,1000,40);
// amarillo
fill(255,255,0);
rect(510,100,40,40);
// morado
fill(255,0,255);
rect(510,200,40,40);
//rojo
fill(255,0,0);
rect(510,300,40,40);
//verde
fill(0,255,0);
rect(510,400,40,40);
fill(255);
//Menos
  text(«Menos», 555, 30);
//Mas
  text(«Más», 940, 30);
//Borrar
  text(«Borrar», 755, 30);
 
  //

  IntVector userList = new IntVector();
  kinect.getUsers(userList);

  if (userList.size() > 0) {
    int userId = userList.get(0);

    if ( kinect.isTrackingSkeleton(userId)) {     
      PVector leftHand = new PVector();
      PVector rightHand = new PVector();
   
     kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftHand);     
     kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, rightHand);
     
    
     // convert real world point to projective space
   
   
    PVector leftHandReal = new PVector();
    kinect.convertRealWorldToProjective(leftHand,leftHandReal);
   
    PVector rightHandReal = new PVector();
    kinect.convertRealWorldToProjective(rightHand,rightHandReal);
   
     println(«LEFT X » +leftHandReal.x + «LEFT Y «+leftHandReal.y);
     println(«RIGHT » + rightHandReal.x+ «RIGHT Y «+rightHandReal.y);  
  
    //Obtener Color
     Pincel(leftHandReal.x,leftHandReal.y);
   
     //Paint
     fill(currentColor);
     if(rightHandReal.x > 60 && rightHandReal.x < 500 && rightHandReal.y>55){
        ellipse(rightHandReal.x,rightHandReal.y,diametro,diametro);     
     }
    
    
    
    }
  }
}

// user-tracking callbacks!
void onNewUser(int userId) {
  println(«start pose detection»);
  kinect.startPoseDetection(«Psi», userId);
}

void onEndCalibration(int userId, boolean successful) {
  if (successful) {
    println(»  User calibrated !!!»);
    kinect.startTrackingSkeleton(userId);
  }
  else {
    println(»  Failed to calibrate user !!!»);
    kinect.startPoseDetection(«Psi», userId);
  }
}

void onStartPose(String pose, int userId) {
  println(«Started pose for user»);
  kinect.stopPoseDetection(userId);
  kinect.requestCalibrationSkeleton(userId, true);
}

void keyPressed(){
  saveFrame(«joint_art_» + random(1000) + «.png»);
}

void Pincel(float posX, float posY) {
 
 
 
  if ((posX>=10)  && (posX<=50) && (posY>=100) && (posY<=140) )
  {
    currentColor = color(255,255,0);
    // amarillo
   
    // amarillo
    fill(255,255,0,30);
    rect(10,100,40,40);

   
}

if ((posX>=10)  && (posX<=50) && (posY>=200) && (posY<=240) )
{
  currentColor = color(255,0,255);
  // morado
fill(255,0,255,30);
rect(10,200,40,40);

}

//fill(127,0,0);rect(60,550,16,16);

if ((posX>=10)  && (posX<=50) && (posY>=300) && (posY<=340) )
{
  currentColor = color(255,0,0);
  //rojo
fill(255,0,0,30);
rect(10,300,40,40);

}

 if ((posX>=10)  && (posX<=50) && (posY>=400) && (posY<=440) )
  {
  currentColor = color(0,255,0);
  //verde
fill(0,255,0,30);
rect(10,400,40,40);
  }
 
  
  if ((posX>=0)  && (posX<=100) && (posY>=0) && (posY<=40) )
  {
  diametro = diametro – 4;
  if(diametro < 0)
  {
    diametro=0;
  }
  }
 
  if ((posX>=400)  && (posX<=500) && (posY>=0) && (posY<=40) )
  {
  diametro = diametro + 4;
  }
 
  if ((posX>=200)  && (posX<=300) && (posY>=0) && (posY<=40) ){
       fill(255,255,255,30); //borrar
       rect(50,40,450,460);
    }

//fill(36,100,19);rect(100,550,16,16);

/*if ((mouseX>90) && (mouseY>540) && (mouseX<110 amp="" br="" mousey="">{
  currentColor = color(36,100,19);
}
*/

}

0 Reviews

There are no reviews yet.