【问题标题】:Get only ONE player in kinect在 kinect 中只获得一名玩家
【发布时间】:2013-02-21 21:06:48
【问题描述】:

我只想通过 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。

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

非常感谢, 迈克尔

【问题讨论】:

  • 需要更多信息。您将更有可能跟踪哪个骨架属于哪个玩家。我们需要GetFirstSkeleton 的代码。看起来您可以通过查看PlayerIndexBitmask 来跟踪玩家,这可能在 1 到 6 之间,因为我相信 Kinect 仅限于 6 玩家跟踪。
  • @Ramhound 我已将其添加到代码中,谢谢

标签: c# wpf tracking kinect


【解决方案1】:

我会看到:

这些解释了玩家检测的全部内容,然后我将只查看 Point-Cloud of Body Using Kinect SDK 以了解该玩家的深度。

【讨论】:

    【解决方案2】:

    Kinect 在 TrackingState == Tracked 中最多返回 2 个骨架,在 PositionOnly 中最多返回 4 个。

    为了追踪骷髅,我使用最接近玩家的方法。

    从骨架中,我保留第一个具有 TrackingState == Tracked 和最小 Position.Z 值。

    这样您就可以避开后面的任何其他骨架,而只专注于完全跟踪的骨架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      • 2019-03-22
      相关资源
      最近更新 更多