This site requires JavaScript, please enable it in your browser!
Greenfoot back
KTG
KTG wrote ...

2011/5/23

Kinect - hand "clicking" and Integer point values

KTG KTG

2011/5/23

#
Hey all, I want to be able to compare the integer values of "joints" for x, y, and z coordinates for some if() statements in my code, any idea how to do that? Also, is it possible to return the coordinate values of a joint in a live, constantly updating stream for a certain join (say, right_hand)? As for the hand "clicking", I'm trying to think of a way of a way to treat my hand passing a certain z value (as it moves towards the camera) as a click of the mouse, but I have absolutely no clue what the coding would be for it. Thanks in advance - KTG
nccb nccb

2011/5/23

#
You can use:
userData.getJoint(Joint.RIGHT_HAND).getX()
to get the X coordinate for the right-hand (you can get a userData from getTrackedUsers in KinectWorld). Once you have that you can do some comparisons. You can use pythagoras for distance calculations, for example:
int xdist = userData.getJoint(Joint.RIGHT_HAND).getX() - targetX;
int ydist = userData.getJoint(Joint.RIGHT_HAND).getY() - targetY;
int straightDist = (int)Math.sqrt(xdist*xdist+ydist*ydist);
if (straightDist < 10) { ... }
This will enter the if block if their hand is less than 10 pixels distance from your target location. If you want to have a stream of data with the positions (or perhaps a stream of those distances), you'll need to build it up yourself by adding to it each act() method, either using an array or a list to hold the stream. Or you can just keep track of how many frames in a row they have managed to keep their hand near the target, e.g.
if (straightDist < 10)
{
    framesNearTarget += 1;
    if (framesNearTarget > 20)
    {
        //Treat this as a click, execute some action
        framesNearTarget = 0;
    }
}
else
{
    // Their hand is not near:
    framesNearTarget = 0;
}
If you want to use a certain Z threshold, you just need:
if (userData.getJoint(Joint.RIGHT_HAND).getZ() < SOME_THRESHOLD)
You'll need to experiment to see what values you get for Z to decide on a threshold. I have a feeling the depth coordinate isn't stunningly precise on the Kinect, so you may find that hovering near a target is a less frustrating experience for the user; most Kinect-based interfaces on the Xbox 360 do something like this, and I suspect it's for good reason.
KTG KTG

2011/5/30

#
(sorry I took so long to respond, my motom blew a few days back and then power got knocked out by storms) Thanks, the coordinate tracking opens up the program a lot! The clicking is still a little sketchy, but that's better than the nothing I had before. You're right, the depth sensing is pretty much garbage with the Kinect. One last thing (for now): I put some shapes into my program and have it so when my right hand is the highest joint, the shape moves right; for my left hand it moves left. Problem is, when I put more than one shape into the program, they all move at the same time. Is there a way to select a shape for an action to be performed upon? That way I can move one shape at a time. Thanks a million! - KTG
You need to login to post a reply.