Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Processing – Kinect Lines

März 1, 2012

Die Tiefeninformationen der Kinect werden verwendet um einzelnen Tiefenflächen zu zeichnen.

/* --------------------------------------------------------------------------
* SimpleOpenNI DepthMap3d Test
* --------------------------------------------------------------------------
* Processing Wrapper for the OpenNI/Kinect library
* http://code.google.com/p/simple-openni
* --------------------------------------------------------------------------
* prog:  Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/
* date:  02/16/2011 (m/d/y)
* ----------------------------------------------------------------------------
*/

import SimpleOpenNI.*;

int linesFrom = 200;
int linesTill = 1000;
int steps = 400;
ArrayList[] points;

SimpleOpenNI context;
float        zoomF =0.6f;
float        rotX = radians(180);  // by default rotate the hole scene 180deg around the x-axis,
// the data from openni comes upside down
float        rotY = radians(0);

void setup()
{
frameRate(300);

size(1024, 768, P3D);  // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem

//context = new SimpleOpenNI(this,SimpleOpenNI.RUN_MODE_SINGLE_THREADED);
context = new SimpleOpenNI(this);

// disable mirror
context.setMirror(false);

// enable depthMap generation
if (context.enableDepth() == false)
{
println("Can't open the depthMap, maybe the camera is not connected!");
exit();
return;
}

stroke(0);
noFill();
smooth();
perspective(radians(45),
float(width)/float(height),
10, 150000);

}

void draw()
{
// update the cam
context.update();

ArrayList[] points = new ArrayList[int(linesTill-linesFrom/steps)];
for(int i = 0;i<points.length;i++){
points[i] = new ArrayList();
}

background(255);

translate(width/2, height/2, 0);
rotateX(rotX);
rotateY(rotY);
scale(zoomF);

int[]   depthMap = context.depthMap();
int     steps   = 3;  // to speed up the drawing, draw every third point
int     index;
PVector realWorldPoint;

translate(0, 0, -1000);  // set the rotation center of the scene 1000 infront of the camera

//stroke(0);

PVector[] realWorldMap = context.depthMapRealWorld();
for (int y=0;y < context.depthHeight();y+=steps)
{
for (int x=0;x = linesFrom && depthMap[index] < linesTill )
{
realWorldPoint = realWorldMap[index];
int index2 = depthMap[index] - linesFrom;
if(index2 % steps == 0) {
points[index2].add(new PVector(realWorldPoint.x, realWorldPoint.y, realWorldPoint.z));
}
//point(realWorldPoint.x, realWorldPoint.y, realWorldPoint.z);  // make realworld z negative, in the 3d drawing coordsystem +z points in the direction of the eye
}
}
}
noFill();
for(int i = 0;i<points.length;i++){
beginShape(TRIANGLE_STRIP);
for(int j = 0;j<points[i].size();j++){
stroke(map(i,0,points.length,0,random(255)));
PVector p = (PVector) points[i].get(j);
vertex(p.x,p.y,p.z);
}
endShape();
}

// draw the kinect cam
//context.drawCamFrustum();
}

void keyPressed()
{
switch(key)
{
case ' ':
context.setMirror(!context.mirror());
break;
}

switch(keyCode)
{
case LEFT:
rotY += 0.1f;
break;
case RIGHT:
// zoom out
rotY -= 0.1f;
break;
case UP:
if (keyEvent.isShiftDown())
zoomF += 0.02f;
else
rotX += 0.1f;
break;
case DOWN:
if (keyEvent.isShiftDown())
{
zoomF -= 0.02f;
if (zoomF < 0.01)
zoomF = 0.01;
}
else
rotX -= 0.1f;
break;
case ENTER:
saveFrame("######.png");
break;
}
}