Reputation: 1
I'm new to Image Processing. How can I track multiple users, using getUserPixels() from Simple OpenNI for Processing? What does this take as parameters? How would I set up this code?
Upvotes: 0
Views: 2405
Reputation: 51837
The idea is to keep track of detected users.
The sceneImage()/sceneMap()
functions are handy to keep track of user pixels, but I also prefer enabling the SKEL_PROFILE_NONE
profile for tracking users.
This works with the onNewUser
and onLostUser
events which return an integer: the id of that user. This id is important to keep track total users or the most recent user detected.
Once you have the user's id you can plug that into other SimpleOpenNI functionalities, like getCoM()
which returns the user's "centre of mass"(the x,y,z position of it's body centre).
So, you would use the above mentioned user events to update an internal list of users:
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
Upvotes: 1