Created
November 24, 2017 03:24
-
-
Save ulrichzwingli/1e8154fa8b1a891bbaa45d1fa6586b04 to your computer and use it in GitHub Desktop.
wip
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.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(640, 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); | |
/* | |
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