我是图像处理的新手。如何使用Simple OpenNI for Processing中的getUserPixels()跟踪多个用户?这作为参数是什么?我该如何设置此代码?
答案 0 :(得分:1)
我们的想法是跟踪检测到的用户。
sceneImage()/sceneMap()
功能可以方便地跟踪用户像素,但我也更喜欢启用SKEL_PROFILE_NONE
个人资料来跟踪用户。
这适用于返回整数的onNewUser
和onLostUser
事件:该用户的ID。此ID对于跟踪总用户或检测到的最新用户非常重要。
获得用户ID后,您可以将其插入其他SimpleOpenNI功能,例如getCoM()
,它返回用户的“质心”(它的身体中心的x,y,z位置)。
因此,您将使用上述用户事件来更新内部用户列表:
import SimpleOpenNI.*;
SimpleOpenNI context;
ArrayList<Integer> users = new ArrayList<Integer>();//a list to keep track of users
PVector pos = new PVector();//the position of the current user will be stored here
void setup(){
size(640,480);
context = new SimpleOpenNI(this);
context.enableDepth();
context.enableScene();
context.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);//enable basic user features like centre of mass(CoM)
}
void draw(){
context.update();
image(context.sceneImage(),0,0);
if(users.size() > 0){//if there are any users
for(int user : users){//for each user
context.getCoM(user,pos);//get the xyz pozition
text("user " + user + " is at: " + ((int)pos.x+","+(int)pos.y+","+(int)pos.z+",")+"\n",mouseX,mouseY);//and draw it on screen
}
}
}
void onNewUser(int userId){
println("detected" + userId);
users.add(userId);//a new user was detected add the id to the list
}
void onLostUser(int userId){
println("lost: " + userId);
//not 100% sure if users.remove(userId) will remove the element with value userId or the element at index userId
users.remove((Integer)userId);//user was lost, remove the id from the list
}
HTH