Ask Your Question

Revision history [back]

Mat image creation from buffer data

Hello,

I have float x, float y, float z values of an image. I want to construct a 16 bit png depth image by copying the z values. The image I am getting as a result has some invalid points. Below is my code.

 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);

Can someone tell me, if I can copy the float values into an unsigned char array to create the image? Is that why my image has invalid points?