简体   繁体   English

OpenCV加载/保存直方图数据

[英]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? 有没有办法将OpenCv图像直方图存储到磁盘,以便可以直接加载,而不必强制再次加载图像并从中计算直方图?

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. 如果要使用c ++ opencv api,还提供了filestorage结构。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM