OpenCV提供了FileStorage类供本地读写数据,其中包括Mat的读写,但是当Mat较大时,读写耗时较大,使用体验较差,代码如下:
Mat img = imread(argv[1], 0);
img.convertTo(img, CV_32F);
blur(img, img, Size(15, 15));
double t1 = getTickCount();
FileStorage fs("./test.xml", FileStorage::WRITE);
fs << "img" << img;
fs.release();
double t2 = getTickCount();
cout << "write xml: " << 1000*(t2-t1)/getTickFrequency() << " ms" << endl;
double t3 = getTickCount();
FileStorage fs2("./test.xml", FileStorage::READ);
Mat t; fs["img"] >> t;
fs2.release();
double t4 = getTickCount();
cout << "read xml: " << 1000*(t4-t3)/getTickFrequency() << " ms" << endl;
cout << " Total xml: " << 100