2
我們目前使用Kinect來跟蹤窗口中的對象,現在我們需要獲取3D而不是「2D」座標。基本上,我們需要在一個點上獲得LockedRect.pBits
的深度值。OpenGL + Kinect SDK - 如何從單個像素獲取深度值?
我們當前的代碼返回隨心所欲0和等,但在這裏它是:
void getDepthData(GLubyte* dest) {
NUI_IMAGE_FRAME imageFrame;
NUI_LOCKED_RECT LockedRect;
if (sensor->NuiImageStreamGetNextFrame(depthStream, 0, &imageFrame) < 0) return;
INuiFrameTexture* texture = imageFrame.pFrameTexture;
texture->LockRect(0, &LockedRect, NULL, 0);
if (LockedRect.Pitch != 0) {
const USHORT* curr = (const USHORT*)LockedRect.pBits;
cout << curr;
const USHORT* dataEnd = curr + (width*height);
while (curr < dataEnd) {
// Get depth in millimeters
USHORT depth = NuiDepthPixelToDepth(*curr++);
// Draw a grayscale image of the depth:
// B,G,R are all set to depth%256, alpha set to 1.
for (int i = 0; i < 3; ++i)
*dest++ = (BYTE)depth % 256;
*dest++ = 0xff;
}
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(depthStream, &imageFrame);
}