1

我只想通过 kinect 跟踪一个人,我想跟踪它的骨骼数据,同时我想显示仅包含该玩家而不包含其他玩家的深度。

此处附上负责该代码的代码,任何人都可以帮忙吗?!

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);
        }

这是生成深度图像的方法:

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;
        }

GetFirstSkeleton 方法的代码

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;
            }
        }

问题是在这里我有所有的玩家,深度图像检测到最多 6 个玩家,而骨架跟踪只有一个,我希望两者中只有一个,同一个玩家。

当我从 player > 0 更改为 player ==1 时,它不起作用,因为播放器并不总是 id 1。

知道如何解决这个问题吗?!

非常感谢,迈克尔

4

2 回答 2

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.

于 2013-02-21T13:06:48.503 回答
0

我会看见:

这些解释了玩家检测的所有内容,然后我会使用 Kinect SDK 的身体点云仅针对该玩家的深度。

于 2012-09-16T22:30:31.657 回答