1

i want to track only one person through the kinect and i wanna track its skeletal data and at the same time i want to show the depth from containing only that player but not the other players.

Attached here is the code responsible for that, CAN anyone HELP ?!!

void mySensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (closing)
                return;

            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }
                byte[] pixels = GenerateDepthImage(depthFrame);

                int stride = depthFrame.Width * 4;
                depthImage.Source =
                    BitmapSource.Create(depthFrame.Width, depthFrame.Height,
                    96, 96, PixelFormats.Bgra32, null, pixels, stride);
            }

            //Get a skeleton
            Skeleton first = GetFirstSkeleton(e);

            ProcessSkeletalData(first, e);
        }

and here is the method of generating depth image:

private byte[] GenerateDepthImage(DepthImageFrame depthFrame)
        {
            //get the raw data from kinect with the depth for every pixel
            short[] rawDepthData = new short[depthFrame.PixelDataLength];
            depthFrame.CopyPixelDataTo(rawDepthData);

            //use depthFrame to create the image to display on-screen
            //depthFrame contains color information for all pixels in image
            //Height x Width x 4 (Red, Green, Blue, empty byte)
            Byte[] pixels = new byte[depthFrame.Height * depthFrame.Width * 4];

            //Bgr32  - Blue, Green, Red, empty byte
            //Bgra32 - Blue, Green, Red, transparency 
            //You must set transparency for Bgra as .NET defaults a byte to 0 = fully transparent

            //hardcoded locations to Blue, Green, Red (BGR) index positions       
            const int BlueIndex = 0;
            const int GreenIndex = 1;
            const int RedIndex = 2;
            const int AlphaIndex = 3;

            //loop through all distances
            //pick a RGB color based on distance
            for (int depthIndex = 0, colorIndex = 0;
                depthIndex < rawDepthData.Length && colorIndex < pixels.Length;
                depthIndex++, colorIndex += 4)
            {
                //get the player (requires skeleton tracking enabled for values)
                int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;

                //gets the depth value
                int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;

                pixels[colorIndex + BlueIndex] = 255;
                pixels[colorIndex + GreenIndex] = 255;
                pixels[colorIndex + RedIndex] = 255;
                pixels[colorIndex + AlphaIndex] = 0;

                //Color all players
                //Debug.WriteLine(player);
                if (player > 0 )
                {
                    pixels[colorIndex + BlueIndex] = 0;
                    pixels[colorIndex + GreenIndex] = 0;
                    pixels[colorIndex + RedIndex] = 0;
                    pixels[colorIndex + AlphaIndex] = 40;
                }
            }
            return pixels;
        }

The code of GetFirstSkeleton MEthod

Skeleton GetFirstSkeleton(AllFramesReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
            {
                if (skeletonFrameData == null)
                    return null;

                skeletonFrameData.CopySkeletonDataTo(allSkeletons);

                //get the first tracked skeleton
                Skeleton first = (from s in allSkeletons
                                  where s.TrackingState == SkeletonTrackingState.Tracked
                                  select s).FirstOrDefault();

                return first;
            }
        }

The problem is here i have all the players UP TO 6 players detected by the depth image while only one by the skeleton tracking and i want to have only one in both, the same player.

When i changed from player > 0 to player ==1 it didn't work because the player is not always with id 1.

Any idea how to solve the matter ?!

Thanks a lot, Michael

casperOne
  • 73,706
  • 19
  • 184
  • 253
Michael Girgis
  • 145
  • 4
  • 14
  • 1
    More information is required. You are going to have keep track of which skeleton belongs to which player more then likely. We need the code for `GetFirstSkeleton`. Looks like you can keep track of the player by looking at `PlayerIndexBitmask` which is likely between 1 and 6 since I believe the Kinect is limited to 6 player tracking. – Security Hound Jul 18 '12 at 15:47
  • @Ramhound I added it to the code, thanks – Michael Girgis Jul 19 '12 at 10:17

2 Answers2

0

I would see:

These explain it all for the player detection, then I would look to Point-Cloud of Body Using Kinect SDK for the depth of that player only.

Community
  • 1
  • 1
Kinected
  • 441
  • 5
  • 19
0

Kinect returns at most 2 skeletons in TrackingState == Tracked, and 4 in PositionOnly.

To track the skeletons I use the closest player approach.

From the Skeletons, I keep the first with TrackingState == Tracked and minimum Position.Z value.

This way you'll avoid any other skeletons in the back, and only focus on full tracked ones.

Rodrigo Rivera
  • 157
  • 1
  • 9