#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Hey Every1, I Need Help With a Kinect V1 Code On Raw Depth Data. Which Syntax's Are Incorrect?

edited December 2017 in Kinect

import org.openkinect.processing.*;

//kinect library object

Kinect kinect;

// Angle for rotation

float a = 0;

void setup(){

size (800,600, P3D);

kinect = new Kinect(this);

kinect.initDepth();

kinect.initDevice();

void draw(){

background(0);

//Translate and rotatate

pushMatrix();

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

rotateY(a);

//we're just going to calculate and draw every 2nd pixel

int skip = 4;

// Get the raw depth as array of integers

int[] depth = kinect.getRawDepth();

stroke(255);

strokeWeight(2);

beginShape(POINTS);

for (int x = 0; x < kinect.depthWidth; x+skip){

for (int y = 0; y < kinect.depthHeight; y+skip) {

int offset = x + y * kinect.depthWidth;

int d = depth[offset];

//calculte the x,y,z camera position based on depth information

PVector point = depthToPointCloudPos(x , y, d);

``````// Draw a point
``````

vertex(point.x, point.y, point.z); } } endShape();

popMatrix();

fill(255);

text(frameRate, 50, 50);

//Rotate

a += 0.0015; }

//calculte the x,y,z camera position based on depth information

PVector depthToPointCloudPos( int x , int y, float depthValue){

PVector point = new Pvector ();

point.z = (depthValue)// / (1.0f); // Convert from mm to meters

point.x = ( x - CameraParams.cx) * point.z / CameraParams.fx;

point.y = ( y - CameraParams.cy) * point.z / CameraParams.fy;

return point;

}

CLASS:

//Camera information based on the kiect hardware static class CameraParams {

static float cx = 254.878f;

static float cy = 205.395f;

static float fx = 365.456f;

static float fy = 365.456f;

static float k1 = 0.0905474;

static float k2 = -0.26819;

static float k3 = 0.0950862;

static float p1 = 0.0;

static float p2 =0.0;

}