做一个小组项目,试图在玩家(特别是玩家)近/远时发生一些事情,所以我们编写了这个函数。 (我们不允许使用骨架特征)
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];
}
}
}
为什么这不能通过抓取一个像素来正确抓取玩家的深度?
最佳答案
深度像素表示为 16 位。低 3 位提供播放器索引,其余 13 位提供深度,例如{深度位}{播放器索引位}
{0100 1011 1001 0}{010}
因此,为了找到播放器索引,我们通过 DepthImageFrame.PlayerIndexBitmask 进行运算,如下所示
(0100 1011 1001 0010) AND (0000 0000 0000 0111) = 0000 0000 0000 0010 = 2 即第二个玩家
为了找到距离,我们向右移动 3 位,返回 13 位,如下所示 0000 1001 0111 0010 = 2418 即 2418 毫米
关于c# - 如何从数据 Kinect SDK C# 中获取播放器深度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9728545/