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;
}
}
}
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 );
but applying the formulas:
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;
the pointcloud obtained is a mess.
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?
thanks in advance
EDIT: i was following also this resource, but it doesn't work for me, because XnDepthPixel contains the real world data in millimeters