Hi, I'm an absolute beginner with Kinect & Processing and I'm stuck with something that I believe should be quite basic stuff. I'm trying to make an interactive video wall so that when a person approaches the wall, color changes. I'm using openKinect and Kinect V2 and in this example code I'm trying to change the color of the ellipse. I managed to map the x coordinates (rx) to color values but I haven't succeeded in mapping the depth values to the color. I'd really appreciate your help!
Here's my code (based on Shiffman's Closest point tracking):
import org.openkinect.processing.*;
// Kinect Library object
Kinect2 kinect2;
float minThresh = 480;
float maxThresh = 830;
PImage img;
void setup() {
size(512, 424);
kinect2 = new Kinect2(this);
kinect2.initDepth();
kinect2.initDevice();
img = createImage(kinect2.depthWidth, kinect2.depthHeight, RGB);
}
void draw() {
background(0);
img.loadPixels();
PImage dImg = kinect2.getDepthImage();
//image(dImg, 0, 0);
// Get the raw depth as array of integers
int[] depth = kinect2.getRawDepth();
int record = 4500;
int rx = 0;
int ry = 0;
for (int x = 0; x < kinect2.depthWidth; x++) {
for (int y = 0; y < kinect2.depthHeight; y++) {
int offset = x + y * kinect2.depthWidth;
int d = depth[offset];
if (d > minThresh && d < maxThresh && x > 100 && y > 50) {
img.pixels[offset] = color(255, 0, 150);
if (d < record) {
record = d;
rx = x;
ry = y;
}
} else {
img.pixels[offset] = dImg.pixels[offset];
}
}
}
img.updatePixels();
image(img,0,0);
float r = map(record, 0, 4500, 0, 255);
fill(r);
ellipse(rx, ry, 60, 60);
}