import SimpleOpenNI.*;
SimpleOpenNI miKinect;
PImage imagenPro;
int [] usuarioId; // int de cada usuario
que sera trackeado
float confianza;
PVector posCabeza=new PVector();
void setup() {
size(640, 480);
fill(255, 0, 0);
stroke(255,0,0);
strokeWeight(3);
miKinect=new SimpleOpenNI(this);
miKinect.enableDepth();
miKinect.enableUser();
}
void draw() {
miKinect.update();
imagenPro=miKinect.depthImage();
image(imagenPro, 0, 0);
usuarioId=miKinect.getUsers(); // conseguir los id de los usuarios
trackeados
for
( int i=0; i<usuarioId.length; i++) { // un loop por cada usuario
if ( miKinect.isTrackingSkeleton( usuarioId[i] ) ) { // El usuario
detectado se ha calibrado correctamente
confianza=miKinect.getJointPositionSkeleton( usuarioId[i],
SimpleOpenNI.SKEL_HEAD, posCabeza);
}
if (confianza>0.5) {
dibujarEsqueleto( usuarioId[i] );
}
}
}
void dibujarEsqueleto( int usuarioId ) {
miKinect.getJointPositionSkeleton(usuarioId, SimpleOpenNI.SKEL_HEAD, posCabeza);
miKinect.convertRealWorldToProjective(posCabeza, posCabeza);
float tam=(500/posCabeza.z)*200;
ellipse(posCabeza.x, posCabeza.y, tam, tam);
//draw limb from head to neck
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
//draw limb from neck to left shoulder
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_LEFT_SHOULDER);
//draw limb from left shoulde to left elbow
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_LEFT_SHOULDER, SimpleOpenNI.SKEL_LEFT_ELBOW);
//draw limb from left elbow to left hand
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_LEFT_ELBOW,
SimpleOpenNI.SKEL_LEFT_HAND);
//draw limb from neck to right shoulder
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_RIGHT_SHOULDER);
//draw limb from right shoulder to right elbow
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_RIGHT_SHOULDER,
SimpleOpenNI.SKEL_RIGHT_ELBOW);
//draw limb from right elbow to right hand
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_RIGHT_ELBOW,
SimpleOpenNI.SKEL_RIGHT_HAND);
//draw limb from left shoulder to torso
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_LEFT_SHOULDER,
SimpleOpenNI.SKEL_TORSO);
//draw limb from right shoulder to torso
miKinect.drawLimb(usuarioId,
SimpleOpenNI.SKEL_RIGHT_SHOULDER, SimpleOpenNI.SKEL_TORSO);
//draw limb from torso to left hip
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_TORSO,
SimpleOpenNI.SKEL_LEFT_HIP);
//draw limb from left hip to left knee
miKinect.drawLimb(usuarioId,
SimpleOpenNI.SKEL_LEFT_HIP,
SimpleOpenNI.SKEL_LEFT_KNEE);
//draw limb from left knee to left foot
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_LEFT_KNEE,
SimpleOpenNI.SKEL_LEFT_FOOT);
//draw limb from torse to right hip
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_TORSO,
SimpleOpenNI.SKEL_RIGHT_HIP);
//draw limb from right hip to right knee
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_RIGHT_HIP,
SimpleOpenNI.SKEL_RIGHT_KNEE);
//draw limb from right kneee to right foot
miKinect.drawLimb(usuarioId, SimpleOpenNI.SKEL_RIGHT_KNEE,
SimpleOpenNI.SKEL_RIGHT_FOOT);
}
void onNewUser(SimpleOpenNI curContext, int
userId)y void onLostUser(SimpleOpenNI curContext, int userId)
No hay comentarios:
Publicar un comentario