2016-08-09 104 views
0

我有float x,float y,float z值的图像。我想通过复制z值构造一个16位png深度图像。我得到的图像有一些无效点。以下是我的代码。从原始缓冲区数据创建原始图像

uint16_t* depthValues = new uint16_t[size]; 
auto sampleVector(DepthPoints); 
for (unsigned int i = 0; i < sampleVector.size(); i++) 
    { 
     depthValues[i] = (sampleVector.at(i).z) * 65536; 
    } 
    Mat newDepthImage = cv::Mat(var.height, var.width, CV_16UC1,depthValues); 
imwrite(Location, CImage); 

可有人告诉我,如果我能浮点值复制到一个unsigned char数组创建图像? 这就是为什么我的图像有无效点?

+0

什么“结果有一些无效点”的确切含义? z值的范围是“[0 - 1]”吗?如果z的值大于1,则大于1的所有值都是65535. – DimChtz

+0

图像的某些区域很暗。我不太确定浮点数据是否可以复制到'uint16_t *'。那是我们如何创建一个深度图像? – MThomas

+0

'z'值的范围是多少?也许所有你需要的是'depthValues [i] = static_cast (sampleVector.at(i).z);'BTW,x,y,z是指R,G,B? – DimChtz

回答

0
auto sampleVector(DepthPoints); 
const int size = sampleVector.size(); 
float* depthValues = new float[size]; 
for (unsigned int i = 0; i < sampleVector.size(); i++) 
    { 
     depthValues[i] = (sampleVector.at(i).z); 
    } 
Mat depthImageOne, depthImageTwo; 
Mat depthImageNew = cv::Mat(var.height, var.width, CV_32FC1,depthValues); 
normalize(newDepthImageNew, depthImageOne, 1, 0, NORM_MINMAX, CV_32FC1); 
depthImageOne.convertTo(depthImageTwo, CV_16UC1, 65536.0,0.0); 
imwrite("path", depthImageTwo); 

规范化可能会导致深度信息丢失。我用图像的可视化规范化。为了保留深度信息,我使用了下面的代码。

Mat depthImageNew = cv::Mat(var.height, var.width, CV_32FC1,depthValues); 
depthImageOne.convertTo(depthImageTwo, CV_16UC1, 1000.0,0.0);