forked from shiffman/libfreenect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple depth thresholding example.
- Loading branch information
1 parent
1d3e502
commit 2e0f185
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
wrappers/java/processing/distribution/openkinect/examples/DepthThreshold/DepthThreshold.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|