Hi
I’m using processing to make some good project.
explanation of project:
Detect hand based on depth and draw the circle on each hand.
Progress:
I can find center but there’s issue.
If two bunch of pixels exist, it’s not what i want it. I want to draw circle on the each hand.
souce code:
// Daniel Shiffman
// Depth thresholding example
// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/
// Original example by Elie Zananiri
// http://www.silentlycrashing.net
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
Kinect kinect;
// Depth image
PImage depthImg;
// Which pixels do we care about?
int minDepth = 60;
int maxDepth = 650;
int forX=0;
// What is the kinect's angle
float angle;
float avgX=0;
float avgY=0;
void setup() {
size(640, 480); //kinect v1 depth re: 320x240
kinect = new Kinect(this);
kinect.initDepth();
angle = kinect.getTilt();
// Blank image
depthImg = new PImage(kinect.width, kinect.height);
}
void draw() {
// Threshold the depth image
int[] rawDepth = kinect.getRawDepth();
float sumX=0,sumY=0;
float total=0;
for(int x=0; x<kinect.width; x++)
{
for(int y=0; y<kinect.height; y++)
{
int offset = x+y*kinect.width;
if (rawDepth[offset] >= minDepth && rawDepth[offset] <= maxDepth) //detect care pixels.
{
depthImg.pixels[offset] = color(255,0,100);
sumX+=x;
sumY+=y;
total++;
}
else
{
depthImg.pixels[offset] = color(0);
}
}
}
// Draw the thresholded image
depthImg.updatePixels();
image(depthImg, 0, 0);
avgX = sumX / total;
avgY = sumY / total;
fill(255,255,100);
ellipse(avgX,avgY,54,54);
fill(255,255,0);
text("TILT: " + angle, 10, 20);
text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
text("avgX: "+int(avgX)+" avgY: " +int(avgY) ,10,60);
}
thank you for reading my question. and Sorry about my English skills… hope you understand.