Ask Your Question

How to write and then read a CV_64FC1 and preserve precision?

asked 2016-04-11 05:44:18 -0500

nyd gravatar image

imread and imwrite apparently don't work with floats, so I should convertto integers, but then, there is no 64bit integer that I could recast to 64bit float. So what do I do?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2016-04-11 05:52:59 -0500

berak gravatar image

updated 2016-04-11 05:54:14 -0500

  • if your opencv libs were compiled with openexr support (check cv::getBuildInformation()), you can save the image as .exr or .hdr . this is the only way with imread/imwrite.
  • you can save it as a text file, using FileStorage:

 Mat floatImg = ...
 FileStorage fs("my.yml", FileStorage::WRITE);
 fs << "myimg" << floatImg;

 Mat floatImg;
 FileStorage fs("my.yml", FileStorage::READ);
 fs["myimg"] >> floatImg;
edit flag offensive delete link more


I went with the second option. Thank you!

nyd gravatar imagenyd ( 2016-04-11 08:56:53 -0500 )edit

Question Tools

1 follower


Asked: 2016-04-11 05:44:18 -0500

Seen: 807 times

Last updated: Apr 11 '16