Created
June 21, 2012 12:45
-
-
Save abcsharp/2965573 to your computer and use it in GitHub Desktop.
https://gist.github.com/2965183 の骨格表示を点から棒人間に変更したバージョン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(5); | |
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_NECK, | |
SimpleOpenNI.SKEL_NECK, | |
SimpleOpenNI.SKEL_LEFT_SHOULDER, | |
SimpleOpenNI.SKEL_LEFT_SHOULDER, | |
SimpleOpenNI.SKEL_LEFT_ELBOW, | |
SimpleOpenNI.SKEL_LEFT_ELBOW, | |
SimpleOpenNI.SKEL_LEFT_HAND, | |
SimpleOpenNI.SKEL_NECK, | |
SimpleOpenNI.SKEL_RIGHT_SHOULDER, | |
SimpleOpenNI.SKEL_RIGHT_SHOULDER, | |
SimpleOpenNI.SKEL_RIGHT_ELBOW, | |
SimpleOpenNI.SKEL_RIGHT_ELBOW, | |
SimpleOpenNI.SKEL_RIGHT_HAND, | |
SimpleOpenNI.SKEL_NECK, | |
SimpleOpenNI.SKEL_TORSO, | |
SimpleOpenNI.SKEL_TORSO, | |
SimpleOpenNI.SKEL_LEFT_HIP, | |
SimpleOpenNI.SKEL_LEFT_HIP, | |
SimpleOpenNI.SKEL_LEFT_KNEE, | |
SimpleOpenNI.SKEL_LEFT_KNEE, | |
SimpleOpenNI.SKEL_LEFT_FOOT, | |
SimpleOpenNI.SKEL_TORSO, | |
SimpleOpenNI.SKEL_RIGHT_HIP, | |
SimpleOpenNI.SKEL_RIGHT_HIP, | |
SimpleOpenNI.SKEL_RIGHT_KNEE, | |
SimpleOpenNI.SKEL_RIGHT_KNEE, | |
SimpleOpenNI.SKEL_RIGHT_FOOT | |
}; | |
for(int i=0;i<joints.length;i+=2){ | |
PVector worldVector1=new PVector(),projVector1=new PVector(),worldVector2=new PVector(),projVector2=new PVector(); | |
context.getJointPositionSkeleton(id,joints[i],worldVector1); | |
context.getJointPositionSkeleton(id,joints[i+1],worldVector2); | |
//実世界座標から投影座標に変換 | |
context.convertRealWorldToProjective(worldVector1,projVector1); | |
context.convertRealWorldToProjective(worldVector2,projVector2); | |
line(projVector1.x,projVector1.y,projVector2.x,projVector2.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