我正在使用OpenNI 1.5.4.0和OpenCV 2.4.5,以及用于可视化目的的Qt (仅限RGB图像)。基本上,我是从Kinect中检索深度和rgb帧,并使用转换将它们存储在硬盘上:
/* 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点云作为后处理计算。我将深度图加载为:
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;得到的点云是一团糟。
如果我进行“在线”处理,直接使用原生XnDepthPixel*数据,使用之前编写的公式,结果是完美的。谁能给我一个关于我的错误的“提示”?
提前感谢
编辑:我也使用了这个resource,但它不适用于我,因为XnDepthPixel包含以毫米为单位的真实数据
发布于 2013-05-12 00:19:11
我认为这里可能存在一个问题:
depth = depth_image.at<int>(j,i); //depth_image is stored as 16bit如果深度图像真的是16位的,那么它应该是:
depth = depth_image.at<short>(j,i); //depth_image is stored as 16bit因为int是32位的,而不是16位。
发布于 2013-05-12 09:14:36
作为补充,如果您构建了支持OpenNI的OpenCV,则可以将深度图像检索为cv::Mat格式,您可以轻松地使用cv::imwrite保存该格式。下面是一个最小的示例:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(){
VideoCapture capture;
capture.open(CV_CAP_OPENNI);
if( !capture.isOpened() ){
cout << "Can not open a capture object." << endl;
return -1;
}
cout << "ready" << endl;
for(;;){
Mat depthMap,depthShow;
if( !capture.grab() ){
cout << "Can not grab images." << endl;
return -1;
}else{
if( capture.retrieve( depthMap, CV_CAP_OPENNI_DEPTH_MAP ) ){
const float scaleFactor = 0.05f;
depthMap.convertTo( depthShow, CV_8UC1, scaleFactor );
imshow("depth",depthShow);
if( waitKey( 30 ) == 115) {//s to save
imwrite("your_depth_naming_convention_here.png",depthShow);
}
}
}
if( waitKey( 30 ) == 27 ) break;//esc to exit
}
}https://stackoverflow.com/questions/16479070
复制相似问题