C++ OpenGL&x2B;Kinect SDK-如何从单个像素获取深度值?
我们目前正在使用Kinect跟踪窗口中的对象,现在我们需要获得3D坐标,而不是“2D”坐标。基本上,我们需要在单个点上通过C++ OpenGL&x2B;Kinect SDK-如何从单个像素获取深度值?,c++,opencv,opengl,kinect,C++,Opencv,Opengl,Kinect,我们目前正在使用Kinect跟踪窗口中的对象,现在我们需要获得3D坐标,而不是“2D”坐标。基本上,我们需要在单个点上通过LockedRect.pBits获得深度值 我们当前的代码返回任意0等,但它是: void getDepthData(GLubyte* dest) { NUI_IMAGE_FRAME imageFrame; NUI_LOCKED_RECT LockedRect; if (sensor->NuiImageStreamGetNextFrame(d
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);
void getDepthData(GLubyte*dest){
NUI_图像_帧图像帧;
NUI_LOCKED_RECT LockedRect;
如果(传感器->NuiImageStreamGetNextFrame(depthStream、0和imageFrame)<0)返回;
INuiFrameTexture*纹理=imageFrame.pFrameTexture;
纹理->LockRect(0,&LockedRect,NULL,0);
如果(锁定俯仰!=0){
const-USHORT*curr=(const-USHORT*)LockedRect.pBits;
无法解锁(0);
传感器->数字图像流释放帧(深度流和图像帧);
}我们找到了一个解决方案!对于任何想知道这一点的人来说,pBits是USHORT格式的最小值,你想找到它后面的第x个像素。在矩阵中描绘它,你想在5*4矩阵中找到深度,例如pBits的下2行和右3列,给你
pBits+2*width+3
=pBits后面的第13位(在纸上可视化有助于实现这一点)
void getDepthData(RotatedRect trackBox,GLubyte*dest){
NUI_图像_帧图像帧;
NUI_LOCKED_RECT LockedRect;
如果(传感器->NuiImageStreamGetNextFrame(depthStream、0和imageFrame)<0)返回;
INuiFrameTexture*纹理=imageFrame.pFrameTexture;
纹理->LockRect(0,&LockedRect,NULL,0);
如果(锁定俯仰!=0){
USHORT*curr=(USHORT*)(LockedRect.pBits);
curr=curr+(USHORT)trackBox.center.y*宽度+(USHORT)trackBox.center.x;
//以毫米为单位获取深度
USHORT深度=NuiDepthPixelToDepth(*curr);
无法使用图像流释放帧(深度流和图像帧);
除此之外,我们的secrifice非常适合1*width+1
差异,这在40+cm距离时不是问题
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);