Multiple Hands Gestures

Back to Tutorials

11. Hand Interaction 13. Skeleton Tracking 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16



This sample is the last regarding the ViiMUnitGesture. In here you can track multiple hands and the system will even recognize each hand's gesture, although being limited to two hands being simultaneously processed (only in the sample! You can have more processing hands at the same time!). But before we head to the code, you will need to first head to the Nite.ini file and make a few changes to get multiple hand recognition to work. The path to this file is: Now you must edit the Nite.ini and make sure it has the following lines:
 * in Windows: C:\Program Files...\PrimeSense\NITE\Hands_1_5_2\Data\Nite.ini
 * in OSX & Linux: /usr/etc/primesense/Hands_1_5_2/Nite.ini
 * [HandTrackerManager]
 * AllowMultipleHands=1
 * TrackAdditionalHands=1
 * UseExtremesTracking=0

After this technical bit, have you checked the image on top of this tutorial? Well, that's exactly how this sample looks like. But if you look closely you can see how it works fine: The hands being tracked at that moment are the #2, #3 and #5, but since the number of processing hands is limited to 2 in this sample, only #2 and #3 are being processed. Comparing the depth and RGB images and the labels on the right we see that: The GUI also shows the position of each hands. Now we're ready to start coding! Starting from the header file, there are two changes we have to make, to make this system compatible with more than one hand: This TrackedHands struct will contain a user's hand [x, y, z] position and ID. You will understand it after the next code block.
 * The #3 hand is making a swipe as seen on the RGB and verified in the label;
 * The #2 hand is closed as seen on the RGB and verified in the label;
 * The #5 hand is not being processed, although is being tracked.

As you can see we use a map to store a hand's id and its TrackedHands struct. In this case the ID variable from the struct and the map's first element are redundant, so we don't use the one from the struct. We just want you to show the available options when programming with ViiM. _handId[10] will store the id of the tracked hands to be printed on the screen.

Now on to the cpp. This sample follows the sample theory as in the previous, only adapted for multiple hands. Because of it, we can set the maximum number of hands to process with In this case we limited the processing to two hands. The extra hands that appear will get to a waiting queue, as we will see later. In some of the event handlers we can observe a few differences, for example in the handCreateHandler: When a new hand is tracked and processed, the event will call this method which will add to the tracked hands map the new hand's position and its ID from the event's handID parameter. Bear in mind that whenever we want to access the hand info, we must tell the map which hand we want to use with its ID. With that in mind, the rest of the code is just like in the previous gesture samples, although adapted to multiple hands. In this sample in specific, since we limited to two simultaneous tracked hands, all the code is focused on deciding whether is the first or second hand. For instance in the swipeRightHandler:

The program only checks if the hand that fired this method is the first or the second element on the map. So if you wanted to have more simultaneous tracked users, you would have to change these parts of the code.

As mentioned before, there is also a hand queue system. Contrary to the other queue system used with the users organization, this queue only works with FIFO (first in the queue, first to get processed once there's space for it). You can find this sample in ViiM_OF_Samples -> src -> Gestures folder.

11. Hand Interaction 13. Skeleton Tracking 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16

Back to Tutorials