kinect replacing background with simpleopenni 1.29

333 views
Skip to first unread message

Tassilo Schwarz

unread,
Nov 4, 2013, 12:29:24 PM11/4/13
to simple-ope...@googlegroups.com
Hi!
I want to replace all user pixels with green. So there's a black backround and in front of the background, there's the silhouette of a person, that is standing in front of the kinect. I found this code, but it's for an old version of SimpleOpenNI; I use SimpleOpenNI 1.29. Is there anybody, who can help me with translating it for the new (1.29) version of SimpleOpenNI? Thank you already!

the code for the old version:
import processing.opengl.*;
import SimpleOpenNI.*;

SimpleOpenNI  kinect;

PImage  userImage;
int userID;
int[] userMap;

PImage rgbImage;
void setup() {
  size(640, 480, OPENGL);

  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();
  kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE); 
}

void draw() {
  background(0); 
  kinect.update();

  // if we have detected any users
  if (kinect.getNumberOfUsers() > 0) { 

    // find out which pixels have users in them
    userMap = kinect.getUsersPixels(SimpleOpenNI.USERS_ALL); 

    // populate the pixels array
    // from the sketch's current contents
    loadPixels(); 
    for (int i = 0; i < userMap.length; i++) { 
      // if the current pixel is on a user
      if (userMap[i] != 0) {
        // make it green
        pixels[i] = color(0, 255, 0); 
      }
    }
    // display the changed pixel array
    updatePixels(); 
  }
}
void onNewUser(int uID) {
  userID = uID;
  println("tracking");
}


Aisling Orr

unread,
Mar 23, 2014, 8:50:52 AM3/23/14
to simple-ope...@googlegroups.com
Did you find an answer to this? I'm having the same problem.

Denis Krueger

unread,
Aug 11, 2014, 8:59:14 AM8/11/14
to simple-ope...@googlegroups.com
This works:

void draw() { 
 kinect.update(); 

 background(0);

 smooth();
  if(kinect.getNumberOfUsers() > 0) { 
    userMap = kinect.userMap();  
    loadPixels();
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        int loc = x + y * width;
        if (userMap[loc] !=0) {           
          pixels[loc] = color(0, 255, 0);
        }
      }
  }  
  updatePixels();
Reply all
Reply to author
Forward
0 new messages