user2438683
user2438683

Reputation: 27

Processing, Simple kinect app don't start a event

I want to do a simple kinect aplication in processing, I just want to when kinect detect a skeleton, show a simple jpeg image, just that. I wrote some code, all works but when someone appears in front of kinect, nothing happens, can anyone help me? This is my code:

import SimpleOpenNI.*;

SimpleOpenNI  kinect;

void setup()
{
  // Começar o evento
  kinect = new SimpleOpenNI(this);

  // Ativar o RGB 
  kinect.enableRGB();

  background(200,0,0);


  // Criar a janela do tamanho do dephMap
  size(kinect.rgbWidth(), kinect.rgbHeight()); 
}

void draw()
{
  // update da camera
  kinect.update();

  // mostrar o depthMap
  image(kinect.rgbImage(),0,0); 

  // Definir quantidade de pessoas
  int i;
  for (i=1; i<=10; i++)
  {
    // Verificar presença da pessoa
    if(kinect.isTrackingSkeleton(i))
    {
      mostrarImagem();  // draw the skeleton
    }
  }
}

// Mostrar a imagem
void mostrarImagem()
{  
 PImage img;
img = loadImage("proverbio1.jpg");
image(img, 0, 0); 
}

Upvotes: 0

Views: 563

Answers (1)

George Profenza
George Profenza

Reputation: 51867

You haven't setup the callbacks for OpenNI user events. Also if you simply want to display an image when someone is detected, you don't actually need to track the skeleton: simply use the scene image. You can get some information about the user's position without tracking the skeleton, like the user's centre of mass. This way you'd have a simpler and faster application if you don't actually need skeleton data.

Here a basic example:

import SimpleOpenNI.*;

SimpleOpenNI context;//OpenNI context
PVector pos = new PVector();//this will store the position of the user
int user;//this will keep track of the most recent user added
PImage sample; 

void setup(){
  size(640,480);
  context = new SimpleOpenNI(this);//initialize
  context.enableScene();//enable features we want to use
  context.enableUser(SimpleOpenNI.SKEL_PROFILE_NONE);//enable user events, but no skeleton tracking, needed for the CoM functionality
  sample = loadImage("proverbio1.jpg");
}
void draw(){
  context.update();//update openni
  image(context.sceneImage(),0,0);
  if(user > 0){//if we have a user
    context.getCoM(user,pos);//store that user's position
    println("user " + user + " is at: " + pos);//print it in the console
    image(sample,0,0);
  }
}
//OpenNI basic user events
void onNewUser(int userId){
  println("detected" + userId);
  user = userId;
}
void onLostUser(int userId){
  println("lost: " + userId);
  user = 0;
}

You can see some handy SimpleOpenNI samples in this Kinect article which is part of a workshop I held last year.

Upvotes: 1

Related Questions