SimpleOpenNI:处理中的多个Kinects和enableScene()/ sceneImage()

时间:2013-01-25 20:11:31

标签: kinect processing openni simple-openni

在Processing中,我可以使用SimpleOpenNI从2个Kinects成功绘制深度图,但我现在正在尝试绘制2个“场景”(来自enableScene()vs enableDepth())。检测到两个Kinect但是当我绘制输出时,我看到相同的场景被绘制两次(而使用enableDepth()总是给我2个不同的深度图像)。我有什么想法我做错了吗?提前谢谢。

/* --------------------------------------------------------------------------
 * 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);
}

1 个答案:

答案 0 :(得分:1)

我使用sceneMap()功能完成了另一个文本,但看起来确实存在SimpleOpenNI内部无法正确更新的问题:

/* --------------------------------------------------------------------------
 * 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();
}

使用类似

的内容
cam1.update();
cam2.update();

而不是

SimpleOpenNI.updateAll();

不会改变任何事情。

issue was filed,希望它会得到解决。 在此期间,尝试在不同的语言/框架中使用OpenNI。 OpenFrameworks与Processing有很多相似之处(和很多不同之处) 老实说,但这不是火箭科学。 尝试实验ofxOpenNI addon to test multiple cameras,希望它能解决您的问题。