如何从Kinect SDK C#数据中获取玩家深度?

4

我正在进行一个小组项目,尝试在玩家(特别是玩家)靠近/远离时触发某些事件,因此我们编写了这个函数。(我们不允许使用骨骼功能)

private void FindDepth(DepthImageFrame depthFrame)
    {

        short[] rawDepthData = new short[depthFrame.PixelDataLength];
        depthFrame.CopyPixelDataTo(rawDepthData);

        Byte[] pixels = new byte[depthFrame.Height * depthFrame.Width * 4];

        for (int depthIndex = 0; depthIndex < rawDepthData.Length; depthIndex++)
        {
            int player = rawDepthData[depthIndex] & DepthImageFrame.PlayerIndexBitmask;
            int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth;

            if (player > 0)
            {
                playerDepth = rawDepthData[depthIndex];
            }

        }

    }

为什么通过抓取一个像素不能正确地获取玩家的深度?
2个回答

3

深度像素使用16位表示。低3位提供玩家索引,其余13位提供深度,例如{深度位}{玩家索引位}

{0100 1011 1001 0}{010}

因此,为了查找玩家索引,我们需要通过DepthImageFrame.PlayerIndexBitmask进行与运算,如下所示

(0100 1011 1001 0010) AND (0000 0000 0000 0111) = 0000 0000 0000 0010 = 2,即第2个玩家

为了找到距离,我们需要向右移3位,返回13位数字,如下所示 0000 1001 0111 0010 = 2418毫米


0

需要记住的是,只有在启用骨架跟踪时,玩家编号值才会添加到深度图像中。如果关闭骨架跟踪,则每个深度值中的玩家编号都将设置为0。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接