Get Specific depth values in Kinect (XNA)

Posted by N0xus on Game Development See other posts from Game Development or by N0xus
Published on 2012-09-25T09:18:56Z Indexed on 2012/09/25 9:49 UTC
Read the original article Hit count: 285

Filed under:
|
|

I'm currently trying to make a hand / finger tracking with a kinect in XNA. For this, I need to be able to specify the depth range I want my program to render. I've looked about, and I cannot see how this is done. As far as I can tell, kinect's depth values only work with pre-set ranged found in the depthStream.

What I would like to do is make it modular so that I can change the depth range my kinect renders. I know this has been down before but I can't find anything online that can show me how to do this.

Could someone please help me out?

I have made it possible to render the standard depth view with the kinect, and the method that I have made for converting the depth frame is as follows (I've a feeling its something in here I need to set)

  private byte[] ConvertDepthFrame(short[] depthFrame, DepthImageStream depthStream, int depthFrame32Length)
    {
        int tooNearDepth = depthStream.TooNearDepth;
        int tooFarDepth     = depthStream.TooFarDepth;
        int unknownDepth    = depthStream.UnknownDepth;
        byte[] depthFrame32 = new byte[depthFrame32Length];


        for (int i16 = 0, i32 = 0; i16 < depthFrame.Length && i32 < depthFrame32.Length; i16++, i32 += 4)
        {
            int player      = depthFrame[i16] & DepthImageFrame.PlayerIndexBitmask;
            int realDepth   = depthFrame[i16] >> DepthImageFrame.PlayerIndexBitmaskWidth;


            // transform 13-bit depth information into an 8-bit intensity appropriate
            // for display (we disregard information in most significant bit)
            byte intensity = (byte)(~(realDepth >> 8));


            if (player == 0 && realDepth == 00)
            {
                // white 
                depthFrame32[i32 + RedIndex]    = 255;
                depthFrame32[i32 + GreenIndex]  = 255;
                depthFrame32[i32 + BlueIndex]   = 255;
            }

         // omitted other if statements. Simple changed the color of the pixels if they went out of the pre=set depth values

            else
            {
                // tint the intensity by dividing by per-player values
                depthFrame32[i32 + RedIndex]    = (byte)(intensity >> IntensityShiftByPlayerR[player]);
                depthFrame32[i32 + GreenIndex]  = (byte)(intensity >> IntensityShiftByPlayerG[player]);
                depthFrame32[i32 + BlueIndex]   = (byte)(intensity >> IntensityShiftByPlayerB[player]);
            }
        }

        return depthFrame32;
    }

I have a strong hunch it's something I need to change in the int player and int realDepth values, but i can't be sure.

© Game Development or respective owner

Related posts about XNA

Related posts about depth-buffer