Basic data persistence and storage
Before finishing this chapter, we will explore the OpenCV functions to store and read our data. In many applications, such as calibration or machine learning, when we finish performing a number of calculations, we need to save these results to retrieve them in subsequent operations. OpenCV provides an XML/YAML persistence layer to this end.
Writing to FileStorage
To write a file with some OpenCV or other numeric data, we can use the FileStorage
class, using a streaming <<
operator such as STL streaming:
#include "opencv2/opencv.hpp" using namespace cv; int main(int, char** argv) { // create our writer FileStorage fs("test.yml", FileStorage::WRITE); // Save an int int fps= 5; fs << "fps" << fps; // Create some mat sample Mat m1= Mat::eye(2,3, CV_32F); Mat m2= Mat::ones(3,2, CV_32F); Mat result= (m1+1).mul(m1+3); // write the result fs << "Result" << result; // release...