我们目前正在使用Kinect跟踪窗口中的对象,现在我们需要获取3D而不是“2D”坐标。基本上,我们需要LockedRect.pBits
在单个点获得的深度值。
我们当前的代码返回任意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);
}
答案 0 :(得分:2)
我们找到了解决方案!对任何想知道同样事情的人; pBits是USHORT格式的最小值,您希望在其后找到第x个像素。在矩阵中描绘它,你想找到深度,例如。在5 * 4矩阵中,pBits向下2行,向下3列,在pBits之后给你pBits + 2 * width + 3
=第13位(在纸上可视化有助于此)。
void getDepthData(RotatedRect trackBox, 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) {
USHORT* curr = (USHORT*)(LockedRect.pBits);
curr = curr + (USHORT)trackBox.center.y * width + (USHORT)trackBox.center.x;
// Get depth in millimeters
USHORT depth = NuiDepthPixelToDepth(*curr);
cout << depth << "\n";
}
texture->UnlockRect(0);
sensor->NuiImageStreamReleaseFrame(depthStream, &imageFrame);
除了我们确实为1*width+1
差异保留了漂亮的代码,这在40 + cm距离内不是问题。