User Tracking

Back to Tutorials

6. Optical Flow 8. Cropping 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16



The ViiMUnitUser is responsible for all information regarding user detection. There are some handy getters available to get information about users on the scene and a setter to restrict the maximum number of users allowed. We can also have events triggered by user related situations.

In this example we will show you exactly that. But before we dive in the good stuff, we advise you to check the first tutorial on using the ViiM engine, the Unit Process tutorial about registering a unit and the Events tutorial where we introduce some of ViiM's events.

This example allows two different modes: scene mode and user mode. In scene mode, although differentiating users, the system returns one single image with alpha channel, where users appear in different tones of gray (gray scale) over the background color. In this mode, user differentiation is not "visible" to the developer. In user mode the differentiation between users is taken one step above, providing one image per user detected (until the user count reaches the maximum number of users allowed). This image has an alpha channel as well and the users are attributed a different color. Due to this separation of users per image, it's possible to define a maximum number of users and special interactions with the program dealing with users in different ways. By default the program starts in user mode, but you can change modes simply by pressing 2 keys, as we will see during this tutorial.

Now we're ready to get to the sample. In the .h the new thing is the definition of a ViiMUnitUser variable. We'll get to it after the .cpp.

In the cpp, before the setup method after the usual showMessage method (log notification), we have two methods used with events related to this unit: These methods will be called when the events regarding this unit are fired. The "link" between called method and trigger event is approached below. The event has a a type (ENTER, LOST, LEAVE or RE_ENTER) and the respective user Id.

In the setup:

We first register the ViiMUnitUser to access all its functionalities. We then get the resolution of the captured images, set a maximum number of users to 2 in line 62 and the time for a user to be considered lost from the system to 1 second. In line 73 we set the far threshold to 3 meters and we choose the type of queue we want for the waiting users in line 81. There are two types of queues: FIFO and CLOSER_USER. FIFO means that the first user that appeared on the waiting queue, will be the first to enter the scene, when there's space for him. CLOSER_USER means that the closest user to the sensor, will be the first one in the waiting queue, thus the first to appear on the scene when there's space for him. Notice that the default type is FIFO. In lines 85 and 86 we set the methods that will be called once the ENTER and LEAVE events are triggered. ENTER means a new user entered the scene and LEAVE is when a user left the scene. In line 89 we define the _isScene flag to false, so the program knows we want it to start in user mode.

in the update method: In the update method we first defined a set of colors in hexadecimal values to use later in the user mode. We then test whether the mode is set to scene or user. If scene mode is selected, we acquire the resulting gray scale image with getScenePixels. If user mode is selected (scene mode not set), we access what users are present in the system with getUsersIds. This will be used to get the pixel information of all users and to achieve different color attribution to users. Using a cycle we get the images from each user with getUserPixels(userId, color) until it reaches the number of users present in the scene with getNumberOfUsers. Each user' image will have some color where the user should be and the rest of the image will be transparent.

The depth image is also acquired in both modes.

In the draw method: In the draw method we test again which mode is set. If scene mode is set, the program displays the scene image with grayscale users and the original depth image. If scene mode is not set, we draw each users' image on the same space. The image of all users will be overlapped, with the user "shadow" having some color and the rest of the image being transparent (with alpha channel). We also added a label with the user's Id. To draw this label we used getCenterOfMass(Id) which returns the center of mass of the user.

and finally the method to change modes with the keyboard: Pressing s will change the mode to scene and pressing u will go back to user. Try this example by yourself on the apps folder, ViiM_OF_Samples and choose your OS.

6. Optical Flow 8. Cropping 1 2  3  4  5  6  7  8  9  10  11  12  13  14  15  16

Back to Tutorials