Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/719348 to your computer and use it in GitHub Desktop.
Save atduskgreg/719348 to your computer and use it in GitHub Desktop.
import shiffman.kinect.*;
PImage img;
PImage depth;
float tolerance = 5;
float targetDepth = 0;
int skip = 2;
void setup() {
size(640,480);
NativeKinect.init();
img = loadImage("shoes.jpg");
img.loadPixels();
depth = createImage(640,480,RGB);
}
static final int gray(color value) {
return max((value >> 16) & 0xff, (value >> 8 ) & 0xff, value & 0xff);
}
void draw() {
NativeKinect.update();
depth.pixels = NativeKinect.getDepthMap();
depth.updatePixels();
if(targetDepth > 0) {
float d = 0;
for(int x = 0; x < 640; x+=skip) {
for(int y = 0; y < 480; y+=skip) {
int loc = x + y * depth.width;
d = gray(depth.pixels[loc]);
if((targetDepth < d + tolerance) && (targetDepth > d - tolerance) ) {
//stroke(0,255,0);
stroke(img.pixels[loc]);
}
else {
stroke(depth.pixels[loc]);
//stroke(0);
}
point(x, y);
}
}
} else {
image(depth,0,0,640,480);
}
}
float depthInInches(float input){
return depthInMeters(input) / 0.0254;
}
float depthInMeters(float rawDepth){
float a = 0.0056748 ;
float b = 0.000083708165 ;
float ccc = 0.6084244 ;
return pow(a +b*rawDepth,-1.0/ccc) / 1000;
}
void mouseClicked() {
targetDepth = gray(depth.pixels[mouseX + mouseY * depth.width]);
println("new target depth: " + depthInInches(targetDepth) + " inches");
background(0);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
tolerance++;
} else if (keyCode == DOWN && tolerance > 0) {
tolerance--;
} else if(keyCode == ENTER){
targetDepth = 0;
}
println("tolerance: " + tolerance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment