Image Array

edited December 2013 in Kinect

Hello. I'm trying to go through an array of images based on the viewer's depth from the kinect. Everything works but it's rather jittery (which I'm open to suggestions on). However if someone jumped in front of the camera, it jumps from image0 to image23, and I wanted to progress through image0 to 23 in order for the images to animate properly, rather than jump.

I think my problem with the code below is that it needs an interval between displaying images because Processing is working too fast and you wouldn't notice a transition from image0 to 23 if you jumped in front of the camera.

Anything would help, thank you guys!

import SimpleOpenNI.*;
SimpleOpenNI  kinect;

float closestValue = 610;
float farthestValue = 2490;
int closestperson;

int pastCurrent;

float pastImage;

float imageRange;
int imageNum;
int imageheight = 480;
int imagewidth = 640;

PImage depthImage;
PImage[] images;


void setup()
{
  size(640, 480);
  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();

  images = new PImage[24];
  for ( int d = 0; d < images.length; d++ )
  {
    images[d] = loadImage(d + ".jpg");
    // make sure images "0.jpg" to "23.jpg" exist
  }

}


void draw()
{


  closestperson = 8000;

  kinect.update();



  int[] depthValues = kinect.depthMap();

  depthImage = kinect.depthImage();


  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 > 610 && currentDepthValue < 2490 && currentDepthValue < closestperson)
        {


          //change closest to new position
          closestperson = currentDepthValue;


          imageRange = (2490 - closestperson) / 78.3;
          imageNum = floor(imageRange);



          //to smoothly change images
          if(imageNum > pastCurrent)
          {
            for(int p = pastCurrent; p <= imageNum; p++)
            {

             //draw the image on screen
             image(images[p], 0, 0);



            }
          }

          if (imageNum < pastCurrent)
          {
            for(int w = pastCurrent; w >= imageNum; w--)
            {
              //draw the image
              image(images[w], 0, 0);

            }

          }

        }



      }
    }


  //update past image
  pastCurrent = imageNum;
} 
Tagged:

Answers

  • edited December 2013

    Hi. I see you are drawing many images in a for loop. This does not work, as you only will see the last one you draw. This happens because the screen is redrawn just once per draw().

    It's like you could only open your eyes once at the end of each draw(). Anything that happens between the end of one draw() and the end of the next draw() is invisible to you. How often this redraw happens is set by frameRate(n).

    I think you should not have for loops. Instead, you could have two if statements.

    In pseudo code, if (currentImage < targetImage) currentImage++; if (currentImage > targetImage) currentImage--; and then just image(images[currentImage], 0, 0); The idea is to take one step from where you are to where you want to be.

Sign In or Register to comment.