1

In Processing, I can successfully draw depth maps from 2 Kinects using SimpleOpenNI, but I'm now trying to draw 2 "scenes" (from enableScene() vs enableDepth()). Both Kinects are detected but when I draw the output, I see the same scene is drawn twice (whereas using enableDepth() always gave me 2 different depth images). Any ideas what I'm doing wrong? Thanks in advance.

/* --------------------------------------------------------------------------
 * SimpleOpenNI Multi Camera Test
 * --------------------------------------------------------------------------
 */

import SimpleOpenNI.*;

SimpleOpenNI cam1;
SimpleOpenNI cam2;

void setup()
{
  size(640 * 2 + 10,480); 

  // start OpenNI, loads the library
  SimpleOpenNI.start();

  // init the cameras
  cam1 = new SimpleOpenNI(0,this);
  cam2 = new SimpleOpenNI(1,this);

  // set the camera generators ** HAD TO REVERSE ORDER FOR BOTH KINECTS TO WORK

  // enable Scene
  if(cam2.enableScene() == false)
  {
     println("Can't open the scene for Camera 2"); 
     exit();
     return;
  }

  // enable depthMap generation 
  if(cam1.enableScene() == false)
  {
     println("Can't open the scene for Camera 1"); 
     exit();
     return;
  }

  background(10,200,20);
}

void draw()
{
  // update the cams
  SimpleOpenNI.updateAll();

  image(cam1.sceneImage(),0,0);

  image(cam2.sceneImage(),640 + 10,0);
}
Gregir
  • 1,574
  • 5
  • 21
  • 43
  • 1
    There were couple of syntax errors with your code which are now fixed, but still, the problems persist. On my machine(old macbook) SimpleOpenNI can't generate the 2nd Kinect's depth map. I'm not sure if it's a USB bus limitation or a problem with the SimpleOpenNI library itself at this point though. – George Profenza Feb 06 '13 at 16:18
  • Very interesting. We've run it on several brand new machines with the Kinects on separate busses, and the simple depth images from enableDepth() work, but the enableScene() on both cams consistently produces the same scene, so I reckon it's something in SimpleOpenNI. Oh, well. Thanks for taking a look. – Gregir Feb 06 '13 at 19:39

1 Answers1

1

I've done another text using the sceneMap() functionality but it looks like there is indeed an issue with SimpleOpenNI not updating properly internally:

/* --------------------------------------------------------------------------
 * SimpleOpenNI Multi Camera Test
 * --------------------------------------------------------------------------
 */

import SimpleOpenNI.*;

SimpleOpenNI cam1;
SimpleOpenNI cam2;

int numPixels = 640*480;
int[] sceneM1 = new int[numPixels];
int[] sceneM2 = new int[numPixels];
PImage scene1,scene2;

void setup()
{
  size(640 * 2 + 10,480 * 2 + 10); 

  // start OpenNI, loads the library
  SimpleOpenNI.start();

  // init the cameras
  cam1 = new SimpleOpenNI(0,this);
  cam2 = new SimpleOpenNI(1,this);

  // set the camera generators ** HAD TO REVERSE ORDER FOR BOTH KINECTS TO WORK

  // enable Scene
  if(cam2.enableScene() == false)
  {
     println("Can't open the scene for Camera 2"); 
     exit();
     return;
  }
//  cam2.enableDepth();//this fails when using only 1 bus

  // enable depthMap generation 
  if(cam1.enableScene() == false)
  {
     println("Can't open the scene for Camera 1"); 
     exit();
     return;
  }
  cam1.enableDepth();

  scene1 = createImage(640,480,RGB);
  scene2 = createImage(640,480,RGB);

  background(10,200,20);
}

void draw()
{
  // update the cams
  SimpleOpenNI.updateAll();

  image(cam1.depthImage(),0,0);
  image(cam1.sceneImage(),0,0);

  cam1.sceneMap(sceneM1);
  cam2.sceneMap(sceneM2);
  updateSceneImage(sceneM1,scene1);
  updateSceneImage(sceneM2,scene2);
  image(scene1,0,490);
  image(scene2,650,490);
}
void updateSceneImage(int[] sceneMap,PImage sceneImage){
  for(int i = 0; i < numPixels; i++) sceneImage.pixels[i] = sceneMap[i] * 255;
  sceneImage.updatePixels();
}

Using something like

cam1.update();
cam2.update();

rather than

SimpleOpenNI.updateAll();

doesn't change anything.

An issue was filed, hopefully it will be resolved. In the meantime, try using OpenNI in a different language/framework. OpenFrameworks has many similarities to Processing (and many differences as well to be honest, but it's not rocket science). Try the experimental ofxOpenNI addon to test multiple cameras, hopefully it will resolve your issue.

George Profenza
  • 50,687
  • 19
  • 144
  • 218
  • Ah, good thinking. One of my coworkers tried this same thing today and got the same results, but that was a good idea. At any rate, I've been wanting to take a look at something like OpenFrameworks or Cinder, so this might be a good opportunity. Thanks again for taking a look at this. (Incidentally, to solve what we were trying to do in the long run with multiple cameras, we went with TSPS as a helper app for the multiple camera stuff, and it worked great. http://opentsps.com/) – Gregir Feb 07 '13 at 15:44