Color mapping

Clearly if you want to visualize the user index data it has to be processed to a more distinct set of colors corresponding to 0 to 7,

The sample program that comes with the SDK uses a hand coded color mapping for each of the 7 colors. A much simpler solution is to map each of the three bits to the three colours R G and B. That is if bit 1 is set then set R to 0xFF i.e. full Red. if bit 2 is set then set G to 0xFF i.e. full green and finally if bit 3 is set then set B to 0xFF i.e. full blue. If any combination of the bits is set then you get a mixture of colors i.e. user 7 gives white.

The program now works in exactly the same way as the Windows Forms version.

An alignment problem

Now we are ready to use the player index as a mask to pick out the player in the video stream. However there is an interesting problem that we have to solve first.

If you simply try to use the player index or the depth field as a mask on the video stream you will discover that they are slightly out of alignment. If you explore this you will also discover that that the amount that they are out of alignment varies according to the distance the user is from the Kinect.

The reason for this is that the video and depth cameras are in slightly different locations and therefore have a different view point. The pixels in the depth and video image don't match up in a simple way.

There is a solution but this is explained in the next chapter.

You can download the code for both the Windows Forms version and the WPF version in a single ZIP file from the CodeBin (note you have to register first).