Skip to content

Instantly share code, notes, and snippets.

@abcsharp
Created June 21, 2012 11:16
Show Gist options
  • Save abcsharp/2965183 to your computer and use it in GitHub Desktop.
Save abcsharp/2965183 to your computer and use it in GitHub Desktop.
simpleOpenNIをつかった骨格検出
import processing.opengl.*;
import SimpleOpenNI.*;
SimpleOpenNI context;
void setup(){
//初期化
context=new SimpleOpenNI(this);
context.setMirror(true);
if(!context.enableDepth()){
println("ERROR!!!!!");
exit();
return;
}
context.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
size(context.depthWidth(),context.depthHeight());//なぜか第3引数をOPENGLにして呼ぶと落ちる
smooth();
strokeWeight(20);
stroke(0,0,0);
}
void draw(){
background(255);
context.update();
//image(context.depthImage(),0,0);
int[] users=context.getUsers();
for(int i=0;i<users.length;i++)
//トラッキング中のスケルトンだったら
if(context.isTrackingSkeleton(users[i]))
//骨格の各部分を描画
drawSkeleton(users[i]);
}
void drawSkeleton(int id){
//配列に全部ぶち込んでアレする
int[] joints={
SimpleOpenNI.SKEL_HEAD,
SimpleOpenNI.SKEL_LEFT_ANKLE,
SimpleOpenNI.SKEL_LEFT_COLLAR,
SimpleOpenNI.SKEL_LEFT_ELBOW,
SimpleOpenNI.SKEL_LEFT_FINGERTIP,
SimpleOpenNI.SKEL_LEFT_FOOT,
SimpleOpenNI.SKEL_LEFT_HAND,
SimpleOpenNI.SKEL_LEFT_HIP,
SimpleOpenNI.SKEL_LEFT_KNEE,
SimpleOpenNI.SKEL_LEFT_SHOULDER,
SimpleOpenNI.SKEL_LEFT_WRIST,
SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_RIGHT_ANKLE,
SimpleOpenNI.SKEL_RIGHT_COLLAR,
SimpleOpenNI.SKEL_RIGHT_ELBOW,
SimpleOpenNI.SKEL_RIGHT_FINGERTIP,
SimpleOpenNI.SKEL_RIGHT_FOOT,
SimpleOpenNI.SKEL_RIGHT_HAND,
SimpleOpenNI.SKEL_RIGHT_HIP,
SimpleOpenNI.SKEL_RIGHT_KNEE,
SimpleOpenNI.SKEL_RIGHT_SHOULDER,
SimpleOpenNI.SKEL_RIGHT_WRIST,
SimpleOpenNI.SKEL_TORSO,
SimpleOpenNI.SKEL_WAIST
};
for(int i=0;i<joints.length;i++){
PVector worldVector=new PVector(),projVector=new PVector();
context.getJointPositionSkeleton(id,joints[i],worldVector);
//実世界座標から投影座標に変換
context.convertRealWorldToProjective(worldVector,projVector);
point(projVector.x,projVector.y);
}
}
void onNewUser(int id){
context.requestCalibrationSkeleton(id,true);
}
void onEndCalibration(int id,boolean successfull){
if(successfull) context.startTrackingSkeleton(id);
else context.startPoseDetection("Psi",id);
}
void onStartPose(String pose,int id){
context.stopPoseDetection(id);
context.requestCalibrationSkeleton(id,true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment