opencv xml read and write

本文介绍了一个使用OpenCV进行XML文件读写的示例程序。该程序演示了如何将不同类型的数据(如整数、矩阵和向量)写入XML文件,并展示了如何从XML文件中读取这些数据。

xml write

FileStorage fs("test1.xml", FileStorage::WRITE);
	fs << "FrameNumber" << 0;


	//map and vector
	string name="test";
	fs << "nest" << "{";
	fs << "Type" <<name ;
	fs << "LeftPoints" << (Mat_<double>(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);

	vector<Point2i> position;
	position.push_back(Point2i(1,1));
	position.push_back(Point2i(2,2));

	fs << "RightPoints" << Mat(position);

	fs << "}";
	
	fs.release();

the output xml

<?xml version="1.0"?>
<opencv_storage>
<FrameNumber>0</FrameNumber>
<nest>
  <Type>test</Type>
  <LeftPoints type_id="opencv-matrix">
    <rows>3</rows>
    <cols>3</cols>
    <dt>d</dt>
    <data>
      1000. 0. 320. 0. 1000. 240. 0. 0. 1.</data></LeftPoints>
  <RightPoints type_id="opencv-matrix">
    <rows>2</rows>
    <cols>1</cols>
    <dt>"2i"</dt>
    <data>
      1 1 2 2</data></RightPoints></nest>
</opencv_storage>


read xml

FileStorage xmlFile("test1.xml", FileStorage::READ);
	int num=xmlFile["FrameNumber"];
	cout<<"FrameNumber " <<num <<endl;
	FileNode fn;
	fn = xmlFile["nest"];

	Mat lp;
	fn["LeftPoints"]>>lp;
	cout<<lp<<endl;

	Mat rp;
	fn["RightPoints"]>>rp;
	cout<<rp<<endl;


tgd@tgd-ECU:~/workspace/newLane/LaneDetection-master$ ./test
FrameNumber0
[1000, 0, 320;
  0, 1000, 240;
  0, 0, 1]
[1, 1;
  2, 2]




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值