Kinect Projection Masking - How to enlarge image to fit a person?

edited March 2017 in Kinect


I'm currently working on an end of year project for university called 'motion tracking projection mapping'.

I'm currently looking into 'projection masking' using the kinect depth image. Basically i'm wanting to project some imagery through a projector and onto a moving person. I have some example code from another site which creates a depth image mask. He later adds the video function to have a video loop onto the person's silhouette. Basically all i'm wanting to do is make the size(); of the window bigger so i can project an enlarged image. However when i'm trying to change the size of the window it doesn't let me as it's something to do with the values being out of bounds of the array. The code im trying to use is in a screenshot attached. Am i able to enlarge the size of the window or is not not possible with kinect 1's 640x480 limitation?

Any help anyone could give me would be greatly appreciated. The code i'm using is below:

Thank you!

import SimpleOpenNI.*; 
SimpleOpenNI  kinect;

int distance = 1500;
int distance2 = 3000;

PImage liveMap;

void setup()
  size(640, 480);
  kinect = new SimpleOpenNI(this);
  liveMap = createImage(640, 480, RGB);

void draw()
  int[] depthValues = kinect.depthMap();
  liveMap.width = 640;
  liveMap.height = 480;
  for (int y=0; y<480; y++) {
    for (int x=0; x<640; x++) {
      int i= x+(y*640);
      int currentDepthValue = depthValues[i];
      if (currentDepthValue>distance&&currentDepthValue<distance2) {
        liveMap.pixels[i] = color(255,255,255);  
      } else {
        liveMap.pixels[i] = color(0,0,0);            


  • Please edit your post (gear icon) and format your code (highlight, CTRL+o)

    it's something to do with the values being out of bounds of the array.

    What is the exact error message? What line of your code does it occur on?

  • Sorry about that jeremydouglass, didn't realise it wasn't properly formatted.

    I'm trying to get an enlarged image of the mask for projection but when i'm trying to enlarge the size i get this error message:

    ArrayIndexOutOfBoundsEpception: 307200 The error is on line 29.

    I'm trying to just type in bigger values in the size setup and replacing the larger values throughout the code, e.g. size(800,800).

    I appreciate that there will be more to change than this but I'm just looking for some guidance on where to go. I'm not wanting to actually change the limitations, just enlarge the image for projection.


  • how big is the array being returned in line 22?

    i would try this

    keep this line the same

    size(640, 480);

    replace all other instances of '640' with 'width' and all other instances of '480' with 'height'. this way everything depends on the values in size and you only have to change them in the one place.

  • edited March 2017 Answer ✓

    oh. the 307200 is the size of the depth values.

    which is, 640x480?

    so you'll have to map the depth value array onto the pixels array, somehow.

    int i= x + (y * width);
    int di = (int)map(x, 0, width, 0, DEPTH_WIDTH) + DEPTH_WIDTH * (int)map(y, 0, height, 0, DEPTH_HEIGHT);
    int currentDepthValue = depthValues[di];

    where DEPTH_WIDTH and DEPTH_HEIGHT are constants that you define that denote the size of the depth values, probably 640 and 480.

    (width and height are processing standard variables set in size())


  • Cool, thanks koogs, i'll have a look into it tonight.

  • Koogs I tried out the code you suggested. I've declared DEPTH_WIDTH and DEPTH_HEIGHT at the top as integers and put in the variables in size(DEPTH_WIDTH,DEPTH_HEIGHT);

    Works fine when just working with the 640,480 size but again when i'm trying to make the window bigger im getting ArrayIndexOutOfBoundsException: 307200 error message where i've replaced the code with your suggestion on line 29.

    Just trying to figure out if there is a way just to enlarge the window and keep all the display the same just enlarge the image which shouldn't really effect the bounds of the array if all i'm wanting to do is just maximise the window.

    Currently trying to figure something out. Again any of your suggestions are greatly appreciated!

  • Answer ✓

    post the current code.

    the problem is that you have a fixed size capture data and a different fixed size screen, you have to map the capture data to the screen.

    originally you used the same index for both pixel arrays (i in lines 29, 31, 33), but you can only do that if the two sizes are the same.

This discussion has been closed.