import org.openkinect.processing.*;
Kinect2 kinect;
int[] depthMapRef;
int[] depthMap;
int Threshold = 50030;
int depthlength;
void setup() {
size(512, 424);
depthlength = 512*424;
kinect
// Raw location
PVector loc = new PVector(0, 0);
// Interpolated location
PVector lerpedLoc = new Kinect2(thisPVector(0, 0);
// kinect.initDepth()Depth data
int[] depth;
void kinect.initDevicesetup(); }{
void drawsize(640, 520);
{ PImage imgdepthlength = 640*480;
kinect = kinect.getDepthImage(new Kinect2(this);
depthMap = kinect.getRawDepthinitDepth();
loadPixelskinect.initDevice();
if (depthMapRef == null new int[depthlength];
}
void draw() {
float depthMapRefsumX = depthMap0;
}float for (int x sumZ = 0;
x < kinect.depthWidth; x++) {
float sumY = 0;
for (int yfloat count = 0;
y
< kinect.depthHeight; y++) {
int loc = x+ y * kinect.depthWidth fill(255, 255, 255, 1);
rect(0, 0, width, height);
PImage img = kinect.getDepthImage();
depthMap = kinect.getRawDepth();
intif difference(depthMapRef = abs(depthMap[loc]-depthMapRef[loc]);
= null) {
if arrayCopy( difference > Threshold) {
depthMap, depthMapRef);
}
pixels[loc] = color(150, 50, 50img.loadPixels();
for (int x = }0; else x < kinect.depthWidth; x++) {
for (int y = pixels[loc] = img.pixels[loc];
}
}
}
updatePixels(0; y < kinect.depthHeight; y++) {
int loc = x+ y * kinect.depthWidth;
int difference = abs(depthMap[loc]-depthMapRef[loc]);
if ( difference > Threshold) {
sumX += x;
sumY += y;
sumZ += depthMap[loc];
count++;
img.pixels[loc] = color(150, 50, 50);
} else {
img.pixels[loc] = img.pixels[loc];
}
}
}
img.updatePixels();
image(img, 0, 0);
// find the average location of the "body mass"
if (count != 0) {
loc = new PVector(sumX/count, sumY/count, sumZ/count);
}
// Interpolating the location with lerp for a smoother animation
lerpedLoc.x = PApplet.lerp(lerpedLoc.x, loc.x, 0.3f);
lerpedLoc.y = PApplet.lerp(lerpedLoc.y, loc.y, 0.3f);
lerpedLoc.z = PApplet.lerp(lerpedLoc.z, loc.z, 0.3f);
fill(255);
text("depth:" +lerpedLoc.z+"", lerpedLoc.x+5, lerpedLoc.y);
ellipse(lerpedLoc.x, lerpedLoc.y, 5, 5);
}
void mousePressed() {
depthMapRef = depthMapbackground(255);
arrayCopy(depthMap, depthMapRef);
}
|