Kinect 从框架数据转换为深度数据,然后再转换回来
Kinect transform from Skeleton data to Depth data and back
我正在试验 kinect API,我正在尝试(和失败)实现以下目标:
首先,我从 Kinect 获取骨架数据,并计算用户右手与 Kinect 的距离
mRightHandPosition = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT];
distance = sqrt(pow(mRightHandPosition.x, 2) + pow(mRightHandPosition.y, 2) + pow(mRightHandPosition.z, 2));
我将右手的骨架数据转换为深度数据,以获得手在(深度/颜色)图像中的位置。
FLOAT curRightX = 0, curRightY = 0;
Vector4 pixelInSkeletonSpace;
NuiTransformSkeletonToDepthImage(mRightHandPosition, &curRightX, &curRightY, cDepthResolution);
获得手的像素位置后,我想将该像素转换回骨架数据,并再次计算该像素(手)中的对象与 Kinect 的距离。我认为这样做应该给我与以前大致相同的距离(当然有一些小误差),但事实并非如此。这是我的工作:
//the position of the depth pixel in the mLockedRect.pBits array
//i have set the depth sensor resolution to 320x240
int pixelPosition = 2 * ((int)curRightX + (int)curRightY * 320);
USHORT p;
//convert the two consecutive bytes to USHORT
p = (((unsigned short)mLockedRect.pBits[pixelPosition]) << 8) | mLockedRect.pBits[pixelPosition + 1];
//get the pixel in skeleton space
pixelInSkeletonSpace = NuiTransformDepthImageToSkeleton(LONG(curRightX), LONG(curRightY), p, cDepthResolution);
//calculate again the distance (which turns out completely wrong)
distance = sqrt(pow(pixelInSkeletonSpace.x, 2) + pow(pixelInSkeletonSpace.y, 2) + pow(pixelInSkeletonSpace.z, 2));
我错过了一些明显的东西吗? 提前致谢
经过大量搜索,我发现了问题所在。这是其他任何试图做类似事情的人的解决方案
首先为了保存深度数据,最好的方法(我发现)如下
在 processDepth() 函数中:
bghr = m_pBackgroundRemovalStream->ProcessDepth(m_depthWidth * m_depthHeight * cBytesPerPixel, LockedRect.pBits, depthTimeStamp);
const NUI_DEPTH_IMAGE_PIXEL* pDepth = reinterpret_cast<const NUI_DEPTH_IMAGE_PIXEL*>(LockedRect.pBits);
memcpy(mLockedBits, pDepth, m_depthWidth * m_depthHeight * sizeof(NUI_DEPTH_IMAGE_PIXEL));
在 ComposeImage() 函数(或要使用深度数据的任何函数)中:
//transform skeleton data point to depth data
NuiTransformSkeletonToDepthImage(mRightHandPosition, &curRightX, &curRightY, cDepthResolution);
//calculate position of pixel in array
int pixelPosition = (int)curRightX + ((int)curRightY * m_depthWidth);
//get the depth value of the pixel
const USHORT depth = mLockedBits[pixelPosition].depth;
//create a new point in skeleton space using the data we got from the previous transformation
pixelInSkeletonSpace = NuiTransformDepthImageToSkeleton(LONG(curRightX), LONG(curRightY), depth << 3, cDepthResolution);
//calculate estimated distance of right hand from the kinect sensor using our recreated data
FLOAT estimated_distance = sqrt(pow(pixelInSkeletonSpace.x, 2) + pow(pixelInSkeletonSpace.y, 2) + pow(pixelInSkeletonSpace.z, 2));
//calculate the distance of the right hand from the kinect sensor using the skeleton data that we got straight from the sensor
FLOAT actual_distance = sqrt(pow(mRightHandPosition.x, 2) + pow(mRightHandPosition.y, 2) + pow(mRightHandPosition.z, 2));
现在,estimated_distance和actual_distance应该具有大致相同的值,但方差很小。
相关文章:
- 将传入的网络"char*"数据转换为"uint8_t"并返回的安全方法是什么?
- PyTorch C++将数据转换为张量失败
- 为 Sql 服务器实现 odbc 包装器.将数据库数据读取为字符或要求驱动程序将数据转换为 C 类型
- 一种将 Dart 中的字节数据转换为 C++ 中的无符号字符*的有效方法?
- 将整数的二进制数据转换为浮点数
- 更改CV_32FC1以CV_64FC1导致不正确的数据转换
- 将JPEG CHAR数据转换为OpenCV垫子
- C++:如何将 32 位数据转换为有符号整数
- 如何将JSON文件中的数据转换为值(double,int ..)
- 如何将 boost::beast 中的序列化数据转换为字符串,以便我可以以 FIFO 方式处理它?
- 将字符串中的二进制数据转换为char
- 如何将提取的字符串数据转换为字符数组
- 如何将XML节点数据转换为QT中的字符串
- Qt:模型/视图框架上的数据转换
- 将Kinect数据转换为OpenCV矩阵
- C - 将UINT8_T*将图像数据转换为双**图像数据
- 数据转换解决方案
- 将点云2数据转换为opencv图像
- 如何将数组中的数据转换为字符串 c++
- C++目录树数据转换为矢量