Created
November 24, 2017 04:38
-
-
Save ulrichzwingli/7d3a05210d698f7dacab788a24eaa899 to your computer and use it in GitHub Desktop.
FYF : Stage 2 : Kinect position tracking (Slow version)
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
import org.openkinect.freenect.*; | |
import org.openkinect.processing.*; | |
// Kinect Library object | |
Kinect kinect; | |
PImage img; | |
float minThresh = 200; | |
float maxThresh = 600; | |
float sumX = 0; | |
float sumY = 0; | |
float totalPixels = 0; | |
void setup() { | |
size(500, 480); | |
kinect = new Kinect(this); | |
kinect.initDepth(); | |
//kinect2.initDevice(); | |
img = createImage(kinect.width, kinect.height, RGB); | |
} | |
void draw() { | |
background(0); | |
img.loadPixels(); | |
//minThresh = map(mouseX, 0, width, 0, 2048); | |
//maxThresh = map(mouseY, 0, height, 0, 2048); | |
// Get the raw depth as array of integers | |
int[] depth = kinect.getRawDepth(); | |
for (int x = 0; x < kinect.width; x++) { | |
for (int y = 0; y < kinect.height; y++) { | |
int offset = x + y * kinect.width; | |
int d = depth[offset]; | |
if (d>minThresh && d<maxThresh) { | |
img.pixels[offset] = color(255, 0, 150); | |
sumX += x; | |
sumY += y; | |
totalPixels ++; | |
} | |
else { | |
img.pixels[offset] = color(0); | |
} | |
} | |
img.updatePixels(); | |
image(img,0,0); | |
float avgX = sumX/ totalPixels; | |
float avgY = sumY/ totalPixels; | |
fill(255); | |
ellipse(avgX, avgY, 20,20); | |
println(avgX + " " + avgY); | |
/* | |
fill(255); | |
textSize(32); | |
text(minThresh + " " + maxThresh, 10,64); | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment