Ask Your Question

Mat image creation from buffer data

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

MariaThomas gravatar image


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] = ( * 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

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

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
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 142 times

Last updated: Aug 09 '16