gpt4 book ai didi

java - 简单的 OpenNI getUserPixels

转载 作者:行者123 更新时间:2023-12-01 14:52:07 25 4
gpt4 key购买 nike

我是图像处理新手。如何使用 Simple OpenNI for Processing 中的 getUserPixels() 跟踪多个用户?这需要什么作为参数?我该如何设置此代码?

最佳答案

这个想法是跟踪检测到的用户。

sceneImage()/sceneMap()函数可以方便地跟踪用户像素,但我也更喜欢启用 SKEL_PROFILE_NONE用于跟踪用户的配置文件。

这适用于 onNewUseronLostUser返回整数的事件:该用户的 ID。此 ID 对于跟踪总用户或最近检测到的用户非常重要。获得用户 ID 后,您可以将其插入其他 SimpleOpenNI 功能中,例如 getCoM()它返回用户的“质心”( body 中心的 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

关于java - 简单的 OpenNI getUserPixels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14742261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com