Is there any way to store an OpenCv image histogram to disk so it can be loaded directly without being forced to load the image again and computing the histogram from it?
Thank you.
Assuming you are working on single channel (gray scale) image, the histogram can be represent by a single channel row matrix which length is equal to the number of bins in your histogram. Then you can easily load/save your histogram from/to a text file. If you want to use c++ opencv api, filestorage structure is also provide. 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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With