userMap questions

I have a doubt on how to access userMap() data and how to manipulate it and convert it to a PGraphics for further manipulation. I did the following code, it works nicely, it differentiates different users(user1, user 2) and fills each silhouette with a different PGraphics. bgG is a PGraphic that i used to fill the background.

void draw() {
  image(bgG, 0, 0);

  kinect.update();

  if (kinect.getNumberOfUsers() > 0) {
    depthValues=kinect.depthMap();
    userMap=kinect.userMap();

    g1.loadPixels();
    g2.loadPixels();
    loadPixels();

    for (int i = 0; i < userMap.length; i++) { 
      switch(userMap[i]) {
      case 1:        
        pixels[i]=g1.pixels[i];
        break;
      case 2:        
        pixels[i]=g2.pixels[i];
        break;
      }
    }
    updatePixels();
  }
}

my questions are: 1. what pixels i'm loading with loadPixels() 2. how can I access each user pixels and use them as mask, or how can i have them converted to a PGraphics or PImage?

My goal is to isolate each user and manipulate their pixel data separately.

thank you

Answers

  • This is to access your loadPixels question:

    Line 12 loads pixels from your (current) sketch. So for example:

    void draw() {
      image(img,0,0,width,height);
      loadPixels();
      for(int i=0;i<img.width*img.height;i++){
        pixels[i]=red(pixels[i]) > 100 ? 255 : 0;
      }
    }
    

    In the above example, pixels array contain the values loaded by loadPixels. Since I draw an image in my sketch, then pixels will have the pixels of my image.

    image(img,0,0,width,height);
    fill(255,0,0);
    ellipse(width/2,height/2,50,50);  
    loadPixels();
    

    In the above example, the pixels array will contain the image and the ellipse, which is drawn right after the image.


    For the second question, accessing pixels in a PGraphics.

    Check this https://forum.processing.org/two/discussion/20761/set-part-of-pgraphics-transparent#latest


    Side comments

    Unfortunately I am not familiar with userMap=kinect.userMap(); If this function returns all the pixels from your device, then you will need to split the image into different PGraphics.

    Related to your code above:

       for (int i = 0; i < userMap.length; i++) { 
          switch(userMap[i]) {
          case 1:        
            pixels[i]=g1.pixels[i];
            break;
          case 2:        
            pixels[i]=g2.pixels[i];
            break;
          }
        }
    

    It is not proper. You example will run fine if PGraphics g1(and g2) has the same size as your current sketch. The size of your current sketch is defined in setup. I cannot help much at this point. Check your references about userMap() and also check if the library provides examples of how to access this user data. By the way, what type of object is userMap in line 8?

    Kf

  • @kfrajer is guess my questions were not that clear, or i couldn't understand your answers.

    the userMap() function is a function that stores the number of users detected by the kinect and it's stored in a int[] array. it is managed under the simpleopenni hood, that manages active users. so in my global variables i just declared int[] userMap. Through this function in the draw i acessed some hidden data that knows what user owns what pixel, so if it's user1, fill it with PGraphics1 and so on. it proved to be faster than scanning each and every pixel of the screen.

    if i understand what you said, the 'lone' loadPixels() is loading all the screen, transforming the pixels and updating the screen. i've tried using bgG.loadPixels() but then the changes were irrevocable, while this lone way it preserves the backround from any change.

    the second part of the question is kinda of reverse of the answer you sent me. i want to create an PGraphics out of each user pixel data, to assign user2 pixels to a user2 PGraphic and then do something of it.

  • it is managed under the simpleopenni hood

    Not many ppl in the forum have your hardware, so they won't know much about your technology. I answered based on information I have gathered from previous posts and from my limited experience working with PGraphics.

    Now:

    Through this function in the draw i acessed some hidden data that knows what user owns what pixel

    I need to see this hidden data. I need to know the nature and dimensions of this data so to be able assign it to your PGraphics object. However, this is not clear from the example that you provided.

    Related to bgC, the changes are irreversible because you are modifying the object directly. However, for the sketch pixels (the 'lone' loadpixels()), they are recreated every time draw() is called, about 30 fps. In other words, the pixels in draw are recreated continuously. It is not that the changes were reversed, is that the scene is recreated every time.

    Please, before you try to use tint or mask in a PGraphics objects, you need to properly assigned the pixels to your PGraphics object. The second question cannot be answered if the first one is not resolved.

    Kf

  • @kfrajer for the first question, i see that i'm managing the whole screen, so if i want to resize it, i just can use a this.resize(newWidth, newHeight), right?

    as this is in a specific kinect forum, i believe people should be used to it. simpleopenni is an abandoned library, it's documentation is well under lousy, even the hardware itself has been discontinued by microsoft.

    btu the real enigma is here. what you said here

    I need to see this hidden data. I need to know the nature and dimensions of this data so to be able assign it to your PGraphics object. However, this is not clear from the example that you provided.

    this is exactly my question. i managed to isolate what pixel belong to what user, and now i want to work with them separately, like remove the red values from user1 and remove green values of user2.

  • if i want to resize it, i just can use a this.resize(newWidth, newHeight),

    I don't think you mean resizing the sketch. You can resize the image right when you draw it or the actual image buffer. For the former, you will use: image(px,py,w,h) where the parameters of this function are defined at https://processing.org/reference/image_.html

    For the latter case, you can copy your current image information (either PGraphics or PImage) into another buffer using either:

    https://processing.org/reference/copy_.html
    https://processing.org/reference/get_.html

    Unfortunately I can't help as much as it is not clear how kinect.userMap(); allows you to pick those pixels from your kinect image. You said:

    i managed to isolate what pixel belong to what user

    It is not clear in your first post how you did that. However, if what you say is true, then making a copy of the information from kinect into your g1 and g2 objects should be one of the steps.

    Did you check previous posts?: https://forum.processing.org/two/search?Search=userMap

    Also these posts are more relevant to your question: https://forum.processing.org/two/discussion/comment/7502/#Comment_7502
    https://forum.processing.org/two/discussion/comment/12206/#Comment_12206
    https://forum.processing.org/two/discussion/11302/multiple-users-in-kinect-processing/p1

    Kf

Sign In or Register to comment.