第十一週課程:頭腳偵測
Week11:Detection head and feet
第一節課(準備)
1. 先下載並安裝 sdk 以及 KinectDeveloperToolkit
2.下載安裝meshlab
3.試試看,範例程式
第二節課(找頭)
1.找尋頭的座標
import SimpleOpenNI.*; 匯入函式庫
SimpleOpenNI show;
void setup()
{
size(640,480);
show=new SimpleOpenNI(this); 要宣告show
show.enableRGB();
show.enableDepth();
show.enableUser();
}
void draw()
{
show.update(); 記得要更新
image(show.userImage(),0,0,640,480);
for(int userId : show.getUsers()) 持續找臉跟畫球
{
PVector pos = new PVector(0,0,0);
float conf=show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,pos);
ellipse(pos.x,pos.y,50,50);
}
}
void onNewUser(SimpleOpenNI curContext, int userId) 記得有人進來要給他一個id
{
curContext.startTrackingSkeleton(userId);
}
SimpleOpenNI show;
void setup()
{
size(640,480);
show=new SimpleOpenNI(this); 要宣告show
show.enableRGB();
show.enableDepth();
show.enableUser();
}
void draw()
{
show.update(); 記得要更新
image(show.userImage(),0,0,640,480);
for(int userId : show.getUsers()) 持續找臉跟畫球
{
PVector pos = new PVector(0,0,0);
float conf=show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,pos);
ellipse(pos.x,pos.y,50,50);
}
}
void onNewUser(SimpleOpenNI curContext, int userId) 記得有人進來要給他一個id
{
curContext.startTrackingSkeleton(userId);
}
第三節課(優化程式)
1.優化找頭程式,讓其更精準
import SimpleOpenNI.*;
SimpleOpenNI show;
void setup()
{
size(640,480);
show=new SimpleOpenNI(this);
show.enableRGB();
show.enableDepth();
show.enableUser();
}
float xpos(PVector pos) 優化
{
return width/2+pos.x*500/pos.z;
}
float ypos(PVector pos) 優化
{
return height/2-pos.y*500/pos.z;
}
void draw()
{
show.update();
image(show.userImage(),0,0,640,480);
for(int userId : show.getUsers())
{
PVector pos = new PVector(0,0,0);
float conf=show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,pos);
ellipse(xpos(pos),ypos(pos),50,50); 優化
}
}
void onNewUser(SimpleOpenNI curContext, int userId)
{
curContext.startTrackingSkeleton(userId);
}
2.增加左右腳
for(int userId : show.getUsers())
{
PVector pos = new PVector(0,0,0),pos1 = new PVector(0,0,0),pos2 = new PVector(0,0,0);
float conf=show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_HEAD,pos);
ellipse(xpos(pos),ypos(pos),50,50);
conf = show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_LEFT_FOOT,pos1);
ellipse(xpos(pos1),ypos(pos1),50,50);
conf = show.getJointPositionSkeleton(userId,SimpleOpenNI.SKEL_RIGHT_FOOT,pos2);
ellipse(xpos(pos2),ypos(pos2),50,50);
}
沒有留言:
張貼留言