2013-03-03 27 views
1

我正試圖通過Kinect深度相機隔離單個玩家。我正在打開一個NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX流來處理玩家/深度信息。我使用畫一個球員的代碼是這樣的:Kinect深度相機中的隔離玩家

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

好的我想通了如何做到這一點。

我需要得到映射到深度像素用戶(1到6)的骨架ID(0到5)。所以當傳感器發現一個骨架時,它保存了ID,並將其設置爲playerId。 PlayerId只有在相關的骨架被傳感器丟失時才被清除。