ofxopenni hand tracking

I was wondering if anyone knows how to retrieve the position of a hand while using the handTracker in gameover’s ofxopenni?

okay, so after adapting some code I found on the forum (Thank you A3-Sh!!), I got the position of the hand to flicker briefly. But it has not returned. Here’s the code I used:

int i = recordHandTracker.getNumTrackedHands();
ofxTrackedHand * tracked = recordHandTracker.getHand(i);

if(tracked != NULL) {
stringstream info;

info << i << " hand position x: "<< tracked->projectPos.x << endl;
info << i << " hand position y: "<< tracked->projectPos.y << endl;

ofDrawBitmapString(info.str(), 20, 560);

}

Any ideas why I cannot get a steady position reading? The tracked variable should not be null because the handTracking ball is clearly visible. I tried playing around with the filtering, but no results there…

Hi,
the ofxHandGenerator class wont retrieve a NULL pointer when using the getHand() method, as the number tracked hands and its corresponding instances of the ofxTrackedHand class are determined and created in the setup.
in your code you were just checking the position of one hand, the last one from the vector that holds hands inside the handTracker, which probably was not tracking any hand.

try using this code:
for(int i =0; i<recordHandTracker.getNumTrackedHands(); i++){
ofxTrackedHand * tracked = recordHandTracker.getHand(i);

if(tracked->isBeingTracked) {
stringstream info;
info << i << " hand position x: "<< tracked->projectPos.x << endl;
info << i << " hand position y: "<< tracked->projectPos.y << endl;
ofDrawBitmapString(info.str(), 20, 560+(i*50));//alter this if the texts is overlapping or getting off screen
}
}

good luck!

1 Like

Thanks!! That worked great.