old code with openkinect doenst work on processing 2.0
in
Contributed Library Questions
•
3 months ago
Hi, im trying to use an old code done with processing 1 in processing 2.
The problem is that in processing 2.0 i dont see anything in the sketch, i just see i black window but i dont see the lines of the program.
The program is suppose to create an obj from the points of the kinect each frame.
any idea why i dont see anything?
here is the code:
- import peasy.*;
- import org.openkinect.*;
- import org.openkinect.processing.*;
- //import superCAD.*;
- boolean record = false;
- float zscale = 3;
- float zskew = 100;
- int inputWidth = 640;
- int inputHeight = 480;
- PeasyCam cam;
- PVector[][] gray = new PVector[inputHeight][inputWidth];
- // We'll use a lookup table so that we don't have to repeat the math over and over
- float[] depthLookUp = new float[2048];
- PImage depth;
- static final int gray(color value) {
- return max((value >> 16) & 0xff, (value >> 8 ) & 0xff, value & 0xff);
- }
- Kinect kinect;
- void setup() {
- size(inputWidth, inputHeight, P3D);
- background(0);
- ///frameRate (60);
- cam = new PeasyCam(this, width*2.5);
- kinect = new Kinect(this);
- kinect.start();
- kinect.enableDepth(true);
- //depth = createImage(640, 480, RGB);
- stroke(255);
- // Lookup table for all possible depth values (0 - 2047)
- for (int i = 0; i < depthLookUp.length; i++) {
- depthLookUp[i] = rawDepthToMeters(i);
- }
- }
- int counter = 0;
- void draw () {
- background(0);
- if (record == true) {
- // beginRaw("superCAD.ObjFile", "objExporter" + counter + ".obj"); //Start recording to the file
- }
- //depth.pixels = NativeKinect.getDepthMap();
- //depth.updatePixels();
- //depth = kinect.getDepthImage();
- int[] depth = kinect.getRawDepth();
- for (int y = 0; y < inputHeight; y++) {
- for (int x = 0; x < inputWidth; x++) {
- int offset = x+y*inputWidth;
- // Convert kinect data to world xyz coordinate
- int rawDepth = depth[offset];
- PVector v = depthToWorld(x,y,rawDepth);
- gray[y][x] = v;
- }
- }
- float scaling = 400;
- // Kyle McDonald’s original source used here
- translate(-inputWidth / 2, -inputHeight / 2,100);
- int step = 2;
- for (int y = step; y < inputHeight; y += step) {
- float planephase = 0.5 - (y-(inputHeight / 2)) / zskew;
- for (int x = step; x < inputWidth; x += step)
- {
- stroke(255);
- //point(x, y, (gray[y][x] - planephase) * zscale);
- PVector v = PVector.mult(gray[y][x],200);
- if (v.z > 100 && v.z < 200) {
- line(v.x,v.y,v.z,v.x,v.y,v.z);
- //line(gray[y][x].x,gray[y][x].y, gray[y][x].z,gray[y][x].x,gray[y][x].y, gray[y][x].z);
- }
- }
- }
- if (record == true) {
- endRaw();
- record = false; // Stop recording to the file
- }
- if (key == 'R' || key == 'r') {
- // Press R to save the file
- record = true;
- counter++; //Thanks to Dr. Rhazes Spell for putting the counter in adding functionality.
- }
- }
- // These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
- float rawDepthToMeters(int depthValue) {
- if (depthValue < 2047) {
- return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
- }
- return 0.0f;
- }
- PVector depthToWorld(int x, int y, int depthValue) {
- final double fx_d = 1.0 / 5.9421434211923247e+02;
- final double fy_d = 1.0 / 5.9104053696870778e+02;
- final double cx_d = 3.3930780975300314e+02;
- final double cy_d = 2.4273913761751615e+02;
- PVector result = new PVector();
- double depth = depthLookUp[depthValue];//rawDepthToMeters(depthValue);
- result.x = (float)((x - cx_d) * depth * fx_d);
- result.y = (float)((y - cy_d) * depth * fy_d);
- result.z = (float)(depth);
- return result;
- }
1