Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV load/save histogram data

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.

like image 358
pparescasellas Avatar asked Dec 20 '22 22:12

pparescasellas


1 Answers

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();
like image 136
Eric Avatar answered Dec 24 '22 03:12

Eric