Loading / Saving OpenCV Histogram Data

Is there a way to save the histogram of an OpenCv image on disk so that it can be loaded directly without being forced to reload the image and calculate the histogram from it?

Thank.

+3
source share
1 answer

Assuming that you are working on an image of a single-channel (gray scale), the histogram can be a matrix of lines in one channel, the length of which is equal to the number of bins on your histogram. Then you can easily load / save your histogram from / to a text file. If you want to use C ++ opencv api, the file system structure is also provided. Read this .

Here is a simple example:

// save file
cv::Mat my_histogram;
cv::FileStorage fs("my_histogram_file.yml", cv::FileStorage::WRITE);
if (!fs.isOpened()) {std::cout << "unable to open file storage!" << std::endl; return;}
fs << "my_histogram" << my_histogram;
fs.release();

// load file
cv::Mat my_histogram;
cv::FileStorage fs("my_histogram_file.yml", cv::FileStorage::READ);
if (!fs.isOpened()) {std::cout << "unable to open file storage!" << std::endl; return;}
fs >> "my_histogram" >> my_histogram;
fs.release();
+10
source

All Articles