Kinect eats my memory

edited October 2013 in Kinect

I have an installation on a store window where an eye is following the people walking outside. But some days it uses all of the computers virtual and physical memory, so it crashes. But can't find anything wrong with the code... (I'm using simple-openni 1.96 and KinectSDK 1.7 and the computer restarts every day)

the eye

The code:

import processing.video.*;
import SimpleOpenNI.*;

SimpleOpenNI  kinect;
Movie  myMovie;

int currentUser = 1;
float clipDuration;
float prevX;
float moveToX;
float moveTo;
int userCount;

float clip_1_start = 0;
float clip_1_end = 109.06;
float clip_1_seq_start = clip_1_start;
float clip_1_seq_end = 12.4;

float clip_2_start = 109.083;
float clip_2_end = 202.116;
float clip_2_seq_start = 131.083;
float clip_2_seq_end = 143.4;

float clip_3_start = 202.133;
float clip_3_end = 293.216;
float clip_3_seq_start = clip_3_start;
float clip_3_seq_end = 215.116;

float current_clip_seq_start;
float current_clip_seq_end;

void setup() {

  size(displayWidth, displayHeight); // Fullscreen

  kinect = new SimpleOpenNI(this);

  if (kinect.isInit() == false)
  {
    println("Can't open the sceneMap, maybe the camera is not connected!");
    exit();
    return;
  }

  kinect.enableDepth();

  kinect.setMirror(true);

  kinect.enableUser();

  myMovie = new Movie(this, "the_eye3.mov");
  myMovie.play();
  myMovie.loop();
  //myMovie.pause();

  // Hide mouse
  noCursor();
}


void draw() {

  background(0);

  // update the cam
  kinect.update();

  image(myMovie, (displayWidth-640)/2, (displayHeight-480)/2);

  // counts users
  userCount = kinect.getNumberOfUsers();


  // draw the center of mass
  PVector pos = new PVector();

  PVector posProjected = new PVector();

  if (myMovie.time() < clip_1_end) {
    current_clip_seq_start = clip_1_seq_start;
    current_clip_seq_end = clip_1_seq_end;
  }
  else if (myMovie.time() < clip_2_end) {
    current_clip_seq_start = clip_2_seq_start;
    current_clip_seq_end = clip_2_seq_end;
  }
  else {
    current_clip_seq_start = clip_3_seq_start;
    current_clip_seq_end = clip_3_seq_end;
  }

  kinect.getCoM(currentUser, pos);

  kinect.convertRealWorldToProjective(pos, posProjected);

  if (pos.x != 0 && pos.z != 0 && pos.y != 0) {

    moveToX = lerp(prevX, posProjected.x, 0.4);

    moveTo = moveToX / (640 / (current_clip_seq_end - current_clip_seq_start)) + current_clip_seq_start;
    myMovie.jump( moveTo );

    prevX = posProjected.x;
  }
}

void mousePressed() {

  myMovie.jump(myMovie.time()+100);
}

// Called every time a new frame is available to read
void movieEvent(Movie m) {
  m.read();
}

// -----------------------------------------------------------------
// SimpleOpenNI user events

void onNewUser(SimpleOpenNI curContext, int userId)
{
  println("NewUser/current: " + userId);
  currentUser = userId;
}

void onLostUser(SimpleOpenNI curContext, int userId) {

  println("LostUser: " + userId);
  if (currentUser == userId) currentUser = 0;
}

void onVisibleUser(SimpleOpenNI curContext, int userId)
{
  //println("onVisibleUser - userId: " + userId);
}
Tagged:

Answers

  • Sorry to be off-topic, but I couldn't resist...

    I find your subject to be very appropriate so close of Halloween... Zombie software!

    I glanced over your code, but I don't know Kinect, so I can't help much, no obvious error there...

    Well, watch out for the println() on events: in the PDE, if the console data is too big, it can stop Processing... If you need the data, better write to a log file. Otherwise, comment them out or have a global boolean variable to display this only in debug mode.

  • edited October 2013

    Hmm .. I am not sure whether it would solve your problem or not but you can try this: Put size(displayWidth,displayHeight, P3D) it makes processing fast. Basically it uses your dedicated graphics to optimize the calculations.

    As PhiLho said avoid printing any unnecessary messages because it creates a lag while printing any message to console.

    finally there is nothing wrong with your code.

  • Thanks to you both for good reply! But removing all print's and using P3D still chrashes the program.

    But this only happens if there are many "users" passing by the Kinect. So I'm trying to restart the program (or just the Kinect sensor). Will this clear the memory and avoid a crash?:

    void reStart() { kinect = null; kinect = new SimpleOpenNI(this); kinect.isInit(); kinect.enableDepth(); kinect.setMirror(true); kinect.enableUser(); }

    (This function is run on a timer)

  • Hi!

    I'm doing a similar project for my final, but I want different clips to play when people walk by. Does anyone know how to do this? I'm not sure how the following functionality is set up:

    if (myMovie.time() < clip_1_end) { current_clip_seq_start = clip_1_seq_start; current_clip_seq_end = clip_1_seq_end;

    I'm relatively new to processing.

    Would be very much appreciated!

  • fabiolaeinhorn: This is playing different parts of the movie by where in the movie the user passes the Kinect.

    If the user passes between clip_2_start and clip_2_end the clip between clip_2_seq_start and clip_2_seq_end is "played".

Sign In or Register to comment.