0

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

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

}
4

1 回答 1

1

你的代码如果没问题,刚刚测试过。它循环了 307200 次,因为它将深度图像 (​​640x480 = 307200) 中的数据转换为 3D 位置。

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

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

}
于 2012-03-06T08:56:00.020 回答