Search code examples
rangekinectprocessingopenni

Kinect SimpleOpenNI and Processing Range


I need to find a way to have the kinect only recognize objects in a certain Range. The problem is that in our setup there will be viewers around the scene who may disturb the tracking. Therefore I need to set the kinect to a range of a few meters so it won't be disturbed by objects beyond that range. We are using the SimpleOpenNI library for processing.

Is there any possibility to achieve something like that in any way?

Thank you very much in advance.

Matteo


Solution

  • You can get the user's centre of mass(CoM) which retrieves a x,y,z position for a user without skeleton detection:

    OpenNI user CoM

    Based on the z position you should be able to use a basic if statement for your range/threshold.

    import SimpleOpenNI.*;
    
    SimpleOpenNI context;//OpenNI context
    PVector pos = new PVector();//this will store the position of the user
    ArrayList<Integer> users = new ArrayList<Integer>();//this will keep track of the most recent user added
    float minZ = 1000;
    float maxZ = 1700;
    
    void setup(){
      size(640,480);
      context = new SimpleOpenNI(this);//initialize
      context.enableScene();//enable features we want to use
      context.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);//enable user events, but no skeleton tracking, needed for the CoM functionality
    }
    void draw(){
      context.update();//update openni
      image(context.sceneImage(),0,0);
      if(users.size() > 0){//if we have at least a user
        for(int user : users){//loop through each one and process
          context.getCoM(user,pos);//store that user's position
          println("user " + user + " is at: " + pos);//print it in the console
          if(pos.z > minZ && pos.z < maxZ){//if the user is within a certain range
            //do something cool 
          }
        }
      }
    }
    //OpenNI basic user events
    void onNewUser(int userId){
      println("detected" + userId);
      users.add(userId);
    }
    void onLostUser(int userId){
      println("lost: " + userId);
      users.remove(userId);
    }
    

    You can find more explanation and hopefully useful tips in these workshop notes I posted.