GENWARE

Biothing's Kernel

Processing ++ Kinect

So….. I got a kinect. :D
I found 2 libraries to work with it in processing:
-Dan Shiffman: http://www.shiffman.net/2010/11/14/kinect-and-processing/
-nocy: https://github.com/nrocy/processing-openkinect

I’m using the later. It seems to work faster but we are still getting some jittering. Apparently people have gotten rid of this problem in OpenFrameworks. The code I’m posting is using a 3d environment where points get the z location based on the depth map. Also, as image and z Depth where not matching perfectly, did some functions for tuning them.

import king.kinect.*;
import peasy.*;
import processing.opengl.*;
import toxi.geom.*;

PeasyCam cam;

PImage img, depth;

int COLS = 640 ;
int ROWS = 480;

jPoint [][] grid = new jPoint[COLS][ROWS];
int dep[][] = new int[COLS][ROWS];
int im[][] = new int[COLS][ROWS];

void setup() {
 size(900, 600,P3D);

 cam = new PeasyCam(this, 100);

 NativeKinect.init();
 NativeKinect.start();

 img = createImage(COLS,ROWS,RGB);
 depth = createImage(COLS,ROWS,RGB);

 int cX = 0;
 int cY = 0;

 for (int i = 0; i < COLS*ROWS; i++) {

 Vec3D ori = new Vec3D(cX,cY,0);
 grid[cX][cY] = new jPoint(ori);
 dep[cX][cY] = 0;
 im[cX][cY] = color(0,0,0);

 cX++;
 if(cX == COLS) {
 cY ++;
 cX = 0;
 }
 }
}

void draw() {

 background(0);
 depth.pixels = NativeKinect.getDepthMap();
 img.pixels = NativeKinect.getVideo();

 //println(brightness(depth.pixels[1]));

 int countX = 0;
 int countY = 0;

 int count = 0;

 for (int i = 0; i < ROWS; i++) {
 for (int j = 0; j < COLS; j++) {
 grid[j][i].run();
 dep[j][i] = depth.pixels[count];
 im[j][i] = img.pixels[count];
 count++;
 }
 }

 for (int i = 0; i < COLS; i++) {
 for (int j = 0; j < ROWS; j++) {

 float depthz = brightness(dep[i][j]);
 float mapDep = map(depthz,0,255,-400,400);
 grid[i][j].loc.z = mapDep;

 //float varX = map(mouseX,0,width,-100,100);   //435
 //float varY = map(mouseY,0,height,-100,100);  //418

 float varX = map(435,0,width,-100,100);
 float varY = map(418,0,height,-100,100);

 int nuX = i + int(varX);
 if(nuX > COLS-1){
 nuX = COLS-1;
 }
 if(nuX < 0){
 nuX = 0;
 }
 int nuY = j + int(varY);
 if(nuY > ROWS-1){
 nuY = ROWS-1;
 }
 if(nuY < 0){
 nuY = 0;
 }

 grid[i][j].mainCol = im[nuX][nuY];
 }
 }

println("mouse X: " + mouseX + ", mouse Y: " + mouseY);

 if(keyPressed) {
 if (key == 's') {
 println("image saved!!!");
 saveFrame("img-####.jpg");
 }
 }
}
class jPoint {

 Vec3D loc;

 color mainCol;

 float cellValue;
 float cellcolR;
 float cellcolG;
 float cellcolB;

 float limit = 300;

 jPoint(Vec3D _loc) {

 loc = _loc;
 }

 void run() {
 display();

 }

 void display() {
 //cellcolR = red(cellCol);
 //cellcolG = green(cellCol);
 //cellcolB = blue(cellCol);

 //stroke(cellcolR,cellcolG,cellcolB);
 //stroke(255);

 stroke(mainCol);
 float mapStr = map(loc.z,0,255,1,5);
 //strokeWeight(mapStr);
 strokeWeight(3);

 //line(loc.x,loc.y,0,loc.x,loc.y,cellcolR*0.02);
 point (loc.x,loc.y, loc.z);
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>