问题描述
我使用OpenNI 1.5.4.0和OpenCV 2.4.5,加上Qt的可视化目的(只有RGB图像)。
基本上,我从Kinect中检索深度和rgb帧,并将它们存储在硬盘驱动器上,使用转换:
i am working with OpenNI 1.5.4.0 and OpenCV 2.4.5, plus Qt for visualization purpose (only RGB images).Basically, i am retrieving the depth and rgb frames from a Kinect and store them on the hard drive, using the conversion:
/* Depth conversion */
cv::Mat depth = cv::Mat(2, sizes, CV_16UC1, (void*) pDepthMap); //XnDepthPixel *pDepthMap
/* RGB conversion */
///image is a QImage* , pImageMap is a XnUInt8*
for(int i = 0; i < height; ++i)
{
for (unsigned y = 0; y < height; ++y)
{
uchar *imagePtr = (*image).scanLine(y);
for (unsigned x=0; x < width; ++x)
{
imagePtr[0] = pImageMap[2];
imagePtr[1] = pImageMap[1];
imagePtr[2] = pImageMap[0];
imagePtr[3] = 0xff;
imagePtr+=4;
pImageMap+=3;
}
}
}
来自硬盘驱动器的那些图像,以便将3D点云计算为后处理计算。
我加载深度映射为:
Now, i want to load those images from hard drive, in order to compute the 3D pointclouds as a post-processing computation.I am loading the Depth maps as:
depth_image = cv::imread(m_rgb_files.at(w).toStdString(), CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR );
,但应用公式:
depth = depth_image.at<int>(j,i); //depth_image is stored as 16bit
p.z = (float)depth * 0.001f; //converting from millimeters to meters
p.x = (float)(i - m_params.center_x) * depth * m_params.focal_length; //focal_length read using OpenNI function
p.y = (float)(j - m_params.center_y) * depth * m_params.focal_length;
所获得的pointcloud是一个混乱。
the pointcloud obtained is a mess.
如果我做在线处理,直接使用本机XnDepthPixel *数据,结果是完美的,使用之前写的公式。
任何人都可以给我一个关于我的错误的提示?
If i do the "online" processing, using directly the native XnDepthPixel* data, the result is perfect, using the formulas written before.Can anybody give me a "hint" about my fault?
提前感谢
:我也是这个,但它不适用于我,因为XnDepthPixel包含以毫米为单位的真实世界数据
i was following also this resource, but it doesn't work for me, because XnDepthPixel contains the real world data in millimeters
推荐答案
我认为这里可能有问题:
I think there is a possible problem here:
depth = depth_image.at<int>(j,i); //depth_image is stored as 16bit
如果深度图像真的是 16位,应该是:
If the depth image really is 16-bit, should it really be:
depth = depth_image.at<short>(j,i); //depth_image is stored as 16bit
因为 int
是32位,而不是16位。
Because int
is 32-bits, not 16.
这篇关于cv :: Mat和XnDepthPixel之间的转换*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!