Skip to content

Commit

Permalink
Added simple depth thresholding example.
Browse files Browse the repository at this point in the history
  • Loading branch information
prisonerjohn committed Feb 12, 2011
1 parent 1d3e502 commit 2e0f185
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Elie Zananiri
// Depth thresholding example
// http://www.silentlycrashing.net

import org.openkinect.*;
import org.openkinect.processing.*;

Kinect kinect;
int kWidth = 640;
int kHeight = 480;
int kAngle = 15;

PImage depthImg;
int minDepth = 60;
int maxDepth = 860;

void setup() {
size(kWidth*2, kHeight);

kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
kinect.tilt(kAngle);

depthImg = new PImage(kWidth, kHeight);
}

void draw() {
// draw the raw image
image(kinect.getDepthImage(), 0, 0);

// threshold the depth image
int[] rawDepth = kinect.getRawDepth();
for (int i=0; i < kWidth*kHeight; i++) {
if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
depthImg.pixels[i] = 0xFFFFFFFF;
} else {
depthImg.pixels[i] = 0;
}
}

// draw the thresholded image
depthImg.updatePixels();
image(depthImg, kWidth, 0);

fill(0);
text("TILT: " + kAngle, 10, 20);
text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
}

void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
kAngle++;
} else if (keyCode == DOWN) {
kAngle--;
}
kAngle = constrain(kAngle, 0, 30);
kinect.tilt(kAngle);
}

else if (key == 'a') {
minDepth = constrain(minDepth+10, 0, maxDepth);
} else if (key == 's') {
minDepth = constrain(minDepth-10, 0, maxDepth);
}

else if (key == 'z') {
maxDepth = constrain(maxDepth+10, minDepth, 2047);
} else if (key =='x') {
maxDepth = constrain(maxDepth-10, minDepth, 2047);
}
}

void stop() {
kinect.quit();
super.stop();
}

0 comments on commit 2e0f185

Please sign in to comment.