在Kinect深度相机中隔离播放器

时间:2013-03-03 03:54:10

标签: c++ kinect

我正试图通过Kinect深度相机隔离单个玩家。我正在打开一个NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX流来处理播放器/深度信息。我用来绘制播放器的代码是:

if (LockedRect.Pitch != 0 ) {
      USHORT* curr = (USHORT*) LockedRect.pBits;
      const USHORT* dataEnd = curr + ((width/2)*(height/2));
      index = 0;

      while (curr < dataEnd && playerId != 0) {
        USHORT depth     = *curr;
        USHORT realDepth = NuiDepthPixelToDepth(depth);
        BYTE intensity = 255;
        USHORT player    = NuiDepthPixelToPlayerIndex(depth);


        // Only colour in the player
        if (player == playerId) {
          for (int i = index; i < index + 4; i++)
            dest[i] = intensity;
        }
        else {
          for (int i = index; i < index + 4; i++)
            dest[i] = 0;
        }
        index += 4;
        curr += 1;                                                                
      }    
 }

dest是一个OpenGL纹理。

我遇到的问题是变量player会在第二个人进入框架时发生变化,并导致纹理中绘制的人成为新人。

1 个答案:

答案 0 :(得分:1)

好的,我想出了怎么做。

我需要获取映射到深度像素用户(1到6)的骨架ID(0到5)。因此,当传感器找到骨架时,它会保存ID,并将其设置为playerId。仅当传感器丢失其相关骨架时,才会清除PlayerId。

相关问题