none
Restricted Pixel Area RRS feed

  • Question

  • Hi,

    I want to check the depth distance of every pixel in restricted area, but i dont know how i can travel by every pixel.

    I know that i need to use a for cycle but i dont know how to determinate a pixel length.

    Thank You

    Friday, May 4, 2012 9:31 AM

All replies

  • hi,

    the SkeletalViewer How To (Get depth data) will help you. Every pixel is in pBufferRun and has 16 bits (highest 3 for player index and lowest 13 for depth).

    Friday, May 4, 2012 10:06 AM
  • public bool CheckForOpenHand(DepthImageFrame depth, Skeleton first)
            {
                float RightHandPX = (first.Joints[JointType.HandRight].Position.X * depth.Width / 2);
                float RightHandPY = (first.Joints[JointType.HandRight].Position.Y * depth.Height / 2);
                float RightWristPX = (first.Joints[JointType.WristRight].Position.X * depth.Width / 2);
                float RightWristPY = (first.Joints[JointType.WristRight].Position.Y * depth.Height / 2);
    
                RightHandPX = CalcPixelX(RightHandPX, depth);
                RightWristPX = CalcPixelX(RightWristPX, depth);
                RightHandPY = CalcPixelY(RightHandPY, depth);
                RightWristPY = CalcPixelY(RightWristPY, depth);
    
                float RefDistanceY = Math.Abs(RightHandPY - RightWristPY);
                float RefDistanceX = Math.Abs(RightWristPX - RightHandPX);
    
                int RefDistance = (int) Math.Round(Math.Max(RefDistanceX, RefDistanceY));
    
                short[] rawDepthData = new short[depth.PixelDataLength];
                depth.CopyPixelDataTo(rawDepthData);
    
                for (int depthIndexY = (int)Math.Round(RightHandPY) - RefDistance; depthIndexY < (int)Math.Round(RightHandPY) + RefDistance; depthIndexY++)
                {
                    for (int depthIndexX = (int)Math.Round(RightHandPX) - RefDistance; depthIndexX < (int)Math.Round(RightHandPX) + RefDistance; depthIndexX++)
                    {
                        int dist = rawDepthData[depthIndexY * depthIndexX];
                        
                        if ((dist < ((first.Joints[JointType.HandRight].Position.Z * 1000) + 50))
                            &&
                            (dist > ((first.Joints[JointType.HandRight].Position.Z * 1000) - 100)))
                        {
                            count++;
                        }
                    }
                }
    
                if (count > RefDistance * 2 * RefDistance * 2 * 20 / 100)
                {
                    count = 0;
                    return true;
                }
                else
                {
                    count = 0;
                    return false;
                }
            }

    this is my code to check if the hand are open or close.

    it just test a area near the hand defined by the distance between the hand joint and the wrist joint. it test every pixel.

    if the distance of one pixel match with the intervel that i insert it increase the counter. at last i compare the counter with the number of pixels  in my area if counter is greater than 20% of the total number of pixels it will return true.

    I had tried somethings, and i think is in the "dist" i think it doesn't giv the right value..

    i am new in that kind of language and amateur in programation.

    my english is to bad.. i hope you can help me.

    Friday, May 4, 2012 3:06 PM
  • Friday, May 4, 2012 5:44 PM