0

I'm using cv::FileStorage to save a float image to hard drive before

cv::FileStorage file(out_path, cv::FileStorage::WRITE);
file << "bla" << img;

This image at the point of saving is a cv::Mat of size 7716*5364 and data type 6, which should be CV_64F. In memory this should take up about 331 megabytes, but when I save this matrix the YAML file takes up about 1.2 gigabytes on the hard drive. Does each value contain that much overhead? I was hoping for FileStorage to do something like numpy.save, where such an array when I save it indeed takes up about 331 megabytes on the hard disk.

smcs
  • 1,772
  • 3
  • 18
  • 48
  • 1
    YAML is ASCII text - it's not efficient. I haven't tried but you should be able to write a 64-bit floating point TIFF, with compression even if disk space is an issue. – Mark Setchell Sep 10 '18 at 17:07
  • check [this](https://stackoverflow.com/a/32357875/5008845) – Miki Sep 10 '18 at 17:13
  • @Miki thanks! I tried it but on compilation I get this error: `undefined reference to CR::matwrite(std::__cxx11::basic_string, std::allocator > const&, cv::Mat const&)'` – smcs Sep 11 '18 at 07:46
  • I retract my statement above concerning 64-bit floating point TIFF - it seems at v3.4.3 of OpenCV it simply writes an 8-bit TIFF with no warning if passed a 64-bit float. – Mark Setchell Sep 12 '18 at 10:35
  • 1
    @Miki I tried out your 64-bit binary saving code, and wanted to let you know you can actually read it back and turn it into a viewable JPEG using **ImageMagick** at the command-line like this `magick -depth 64 -define quantum:format=floating-point -size 5364x7716+16 gray:image.bin -evaluate divide 100 result.jpg` Pretty neat as it means your format is somewhat *portable*! The `+16` skips the 16-bytes of rows, columns, type and mode that you have at the start. – Mark Setchell Sep 12 '18 at 11:09
  • @MarkSetchell yeah, that was what I read--32bit seems to be the maximum for `imwrite()`. And that's apparently for three colour channels. I couldn't get Miki's code to work so far, for writing, the first answer here worked well: https://stackoverflow.com/questions/16312904/how-to-write-a-float-mat-to-a-file-in-opencv I don't know yet how to read it back into a `cv::Mat` though. – smcs Sep 12 '18 at 11:16
  • 1
    @speed you probably need to put the functions declaration in a header file, or forward declare the functions. Hard to tell without seeing the code you're using. – Miki Sep 12 '18 at 11:40
  • 1
    @MarkSetchell Nice! Thanks for letting me know :) – Miki Sep 12 '18 at 11:41
  • 1
    Try clicking `edit` under your question and adding the simplest possible example using Miki’s code so we can take a look. – Mark Setchell Sep 12 '18 at 11:42

0 Answers0