OpenCV开发——Yml文件的读取与写入

Home / C++ MrLee 2015-8-22 2818

学习OpenCV中文版封面

结果 test.yml

xml">%YAML:1.0 i: 5 r: 3.1000000000000001e+000 str: ABCDEFGH lena: !!opencv-matrixrows: 512 //lena的身高cols: 512 //lena的三围(正方形?惊!)dt: "3u"data: [ lena的数字版裸体。。。。。。][/cpp]
/***********************************************************************
 * OpenCV 2.1 example
 * By Pebbler Chung 2010
 ***********************************************************************/
 
#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(readfs.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:"< 

本文链接:https://www.it72.com/4714.htm

推荐阅读
最新回复 (0)
返回