opencv xml read and write

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]




你可能感兴趣的:(opencv xml read and write)