Ask Your Question
0

Mat image creation from buffer data

asked 2016-08-09 10:21:24 -0600

MariaThomas gravatar image

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-09 17:41:32 -0600

Tetragramm gravatar image

It's possible some of the float values are outside of the range. Use cv::saturate_cast<uint16_t>() to safely convert them to ushorts.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-09 10:21:24 -0600

Seen: 350 times

Last updated: Aug 09 '16