使用Kinect的simpleopenni点云程序

时间:2012-03-06 03:52:53

标签: processing kinect point-clouds

我正在尝试使用处理来获取点云。但事实证明它不起作用

import SimpleOpenNI.*;

import processing.opengl.*;

SimpleOpenNI kinect;

void setup()
{

  size( 1024, 768, OPENGL);

  kinect = new SimpleOpenNI( this );

  kinect.enableDepth();

}

void draw()
{

  background( 0);

  kinect.update();

  translate( width/2,  height/2, -1000);

  rotateX( radians(180));

 stroke(255);

  PVector[] depthPoints = kinect.depthMapRealWorld();

  //the program get stucked in the for loop it loops 307200 times and I don't have any points output

  for( int i = 0; i < depthPoints.length ; i++)
  {

    PVector currentPoint = depthPoints[i];

    point(currentPoint.x,  currentPoint.y, currentPoint.z );
  }

}

1 个答案:

答案 0 :(得分:1)

你的代码很好,只是经过测试。 它循环307200次,因为它将深度图像(640x480 = 307200)中的数据转换为3D位置。

您确定没有收到任何错误吗? 另外,在Processing中绘制所有点有点慢,你可能想跳过一些。 并且作为测试,尝试打印出第一个点并查看值是否会发生变化(它应该) 或者如果深度图像有任何数据(不是黑色/用零填充):

import SimpleOpenNI.*;

import processing.opengl.*;

SimpleOpenNI kinect;

void setup()
{

  size( 1024, 768, OPENGL);

  kinect = new SimpleOpenNI( this );

  kinect.enableDepth();

}

void draw()
{

  background( 0);

  kinect.update();
  image(kinect.depthImage(),0,0,160,120);//check depth image

  translate( width/2,  height/2, -1000);

  rotateX( radians(180));

  stroke(255);

  PVector[] depthPoints = kinect.depthMapRealWorld();

  //the program get stucked in the for loop it loops 307200 times and I don't have any points output

  for( int i = 0; i < depthPoints.length ; i+=4)//draw point for every 4th pixel
  {

    PVector currentPoint = depthPoints[i];
    if(i == 0) println(currentPoint);
    point(currentPoint.x,  currentPoint.y, currentPoint.z );
  }

}