#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace cv; //下面的所有cv相关类型不用加上前缀了
int main(int argc, char* argv[])
{
FileStorage fs("test.yml", FileStorage::WRITE); //写的形式打开yml。当然也可以打开xml,主要看后缀
fs << "i" << 5 << "r" << 3.1 << "str" << "ABCDEFGH"; //存入整型、浮点型、字符串
Mat writeInImg = imread( "lena.jpg" ); //载入Lena妞的图片载入
imshow( "Lena_from_jpg", writeInImg ); //看一看Lena妞是否健在
fs << "lena" << writeInImg; //将Lena妞的图片矩阵插入test.yml
fs.release();
FileStorage readfs("test.yml", FileStorage::READ); //读的形式打开yml。当然也可以打开xml,主要看后缀
if( imgRecall.isOpened() )
{
int i1 = (int)readfs["i"];
double r1 = (double)readfs["r"];
string str1 = (string)readfs["str"];
Mat readOutImg;
readfs["lena"] >> readOutImg; //把Lena从yml中取出
imshow( "Lena_from_yml", readOutImg ); //看看是不是跟之前放进去的是同一个人
cout<<"read out i:"<<i1<<endl<<"read out r:"<<r1<<endl<<"read out str:"<<str1<<endl;
}
readfs.release();
waitKey();
return 0;
}
C++版本 yml 文件的读取 based on OpenCV 2.1
最新推荐文章于 2024-10-16 17:51:19 发布