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
在第二個人進入框架時發生變化,並使得在紋理中繪製的人成爲新人。