Emulating Button Press Using Kinect/SimpleOpenNI + Processing Depth

Posted by Alex Lu on Stack Overflow See other posts from Stack Overflow or by Alex Lu
Published on 2012-07-18T21:56:13Z Indexed on 2012/11/08 11:02 UTC
Read the original article Hit count: 267

Filed under:
|
|

I am using Kinect with Simple OpenNI and Processing, and I was trying to use the Z position of a hand to emulate a button press. So far when I try it using one hand it works really well, however, when I try to get it to work with a second hand, only one of the hands work. (I know it can be more efficient by moving everything except the fill out of the if statements, but I kept those in there just in case I want to change the sizes or something.)

irz and ilz are the initial Z positions of the hands when they are first recognized by onCreateHands and rz and lz are the current Z positions. As of now, the code works fine with one hand, but the other hand will either stay pressed or unpressed. If i comment one of the sections out, it works fine as well.

if (rz - irz > 0) {
 pushStyle();
 fill(60);
 ellipse(rx, ry, 10, 10);
 popStyle();
 rpressed = true;
}
else {
 pushStyle();
 noFill();
 ellipse(rx, ry, 10, 10);
 popStyle();
 rpressed = false;
}

if (lz - ilz > 0) {
 pushStyle();
 fill(60);
 ellipse(lx, ly, 10, 10);
 popStyle();
 lpressed = true;
}
else {
 pushStyle();
 noFill();
 ellipse(lx, ly, 10, 10);
 popStyle();
 lpressed = false;
}

I tried outputting the values of rz - irz and lz - ilz and the numbers range from small negative values to small positive values (around -8 to 8) for lz - ilz. But rz - irz outputs numbers from around 8-30 depending on each time I run it and is never consistent. Also, when I comment out the code for the lz-ilz, the values for rz-irz look just fine and it operates as intended. Is there a reason tracking both Z positions throws off one hand? And is there a way to get it to work?

Thanks!

© Stack Overflow or respective owner

Related posts about processing

Related posts about Kinect