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:
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();
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();
source
share