Question

I am trying to use processing to get the point cloud. But it turn out that it does not work

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

}
Was it helpful?

Solution

Your code if fine, just tested. It loops 307200 times because it converts data from the depth image (640x480 = 307200) into 3D positions.

Are you sure you're not getting any errors ? Also, drawing all the points in Processing is a bit slow, you might want to skip a few. And as test, try to print out the 1st point and see if the value changes at all (it should) or if the depth image has any data (isn't black/filled with zeroes):

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

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top