存储
then
int main(){//创造一些要存的数据先 string words = "hello, my guys!"; float n = 3.1415926; Mat m = Mat::eye(3, 3, CV_32F); //开始创建存储器 FileStorage save("data.yml", FileStorage::WRITE);// 你也可以使用xml格式 save << "words" << words; save << "number" << n; save << "matrix" << m; save.release(); //存储完毕 cout << "finish storing" << endl;
加载
//加载数据,类似Python字典的用法,创建加载器 FileStorage load("data.yml", FileStorage::READ); float nn; Mat mm; string ww; load["words"] >> ww; load["number"] >> nn; load["matrix"] >> mm; cout<< ww << endl << nn << endl << mm; cout << endl << "That's the end"; load.release(); return 0;}
完整代码
#include