[SimpleOpenNI] How to set image pixels as silhouette?
in
Contributed Library Questions
•
10 months ago
Hi all!
I'm trying to change a little bit of the SimpleOpenNI example that separate user pixels from background to set pixels from an image inside the silhouette of users.
Here's my code (doesn't work, pixels are only black)
- import SimpleOpenNI.*;
- SimpleOpenNI kinect;
- boolean tracking = false;
- int userID;
- int[] userMap;
- void setup() {
- size(600, 480);
- kinect = new SimpleOpenNI(this);
- kinect.enableDepth();
- // enable color image from the Kinect
- kinect.enableRGB();
- kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);
- // turn on depth-color alignment
- kinect.alternativeViewPointDepthToImage();
- // load the background image
- backgroundImage = loadImage("lua.jpg");
- }
- void draw() {
- // display the background image
- background(0);
- kinect.update();
- if (tracking) {
- // get the Kinect color image
- PImage rgbImage = loadImage("empire_state.jpg");
- // prepare the color pixels
- rgbImage.loadPixels();
- loadPixels();
- userMap = kinect.getUsersPixels(SimpleOpenNI.USERS_ALL);
- for (int i =0; i < userMap.length; i++) {
- for (int j = 0; j < rgbImage.pixels.length; j++) {
- color c = rgbImage.pixels[j];
- float r = red(c);
- float g = green(c);
- float b = blue(c);
- // if the pixel is part of the user
- if (userMap[i] != 0) {
- // set the sketch pixel to the color pixel
- pixels[i] = color((r + g + b) / 3);
- }
- }
- }
- rgbImage.updatePixels();
- updatePixels();
- }
- }
- void onNewUser(int uID) {
- userID = uID;
- tracking = true;
- println("tracking");
- }
Any ideas?
1