opencv 读写xml文件

void writeCameraParamsXML()
{
	FileStorage fs("cameraParams.xml", FileStorage::WRITE);
	//开始文件写入
	fs << "frameCount" << 20;
	time_t rawtime;
	time(&rawtime);
	fs << "calibrationDate" << asctime(localtime(&rawtime));

	Mat cameraMatrixL = (Mat_<double>(3, 3) << 269.7783887712764, 0, 151.0565879797926,
		0, 267.0670770707237, 103.2889641857869,
		0, 0, 1);

	Mat distCoeffL = (Mat_<double>(5, 1) << 3.292753725003047e-05,
		0.3334558546209874,
		-0.0007762980542583555,
		0.002768478869536125,
		-1.022355978205538);

	Mat cameraMatrixR = (Mat_<double>(3, 3) << 269.1356478541644, 0, 158.509582761769,
		0, 266.4233661647525, 122.2878154003198,
		0, 0, 1);

	Mat distCoeffR = (Mat_<double>(5, 1) << -0.002516093790587057,
		0.5080801263588319,
		0.00159686792699245,
		0.00447049258279624,
		-1.911823270199251);

	Mat Rl = (Mat_<double>(3, 3) << 0.9990638869827868, -0.01888052892505704, 0.0389213996967679,
		0.0141542003027198, 0.9928750152118871, 0.1183167899403338,
		-0.04087796889078475, -0.1176551307657455, 0.9922128107739082);

	Mat Rr = (Mat_<double>(3, 3) << 0.9991055369603488, -0.01260449834282734, -0.04036400174287882,
		0.01498925630502581, 0.998125615280672, 0.05933446145371164,
		0.03954046295373517, -0.0598864153385842, 0.9974217608651312);

	Mat Pl = (Mat_<double>(3, 4) << 268.7616960851367, 0, 124.6051635742188, 0,
		0, 268.7616960851367, 97.82008457183838,
		0, 0, 0, 1, 0);

	Mat Pr = (Mat_<double>(3, 4) << 268.7616960851367, 0, 124.6051635742188, 0,
		0, 268.7616960851367, 97.82008457183838, 8326.861924888874,
		0, 0, 1, 0);

	Mat T = (Mat_<double>(1, 3) << 0.4644, 30.9243, 1.8383);

	fs << "cameraMatrixL" << cameraMatrixL << "distCoeffL" << distCoeffL;
	fs << "cameraMatrixR" << cameraMatrixR << "distCoeffR" << distCoeffR;
	fs << "Rl" << Rl << "Pl" << Pl;
	fs << "Rr" << Rr << "Pr" << Pr;
	fs << "T" << T;

	fs.release();
	std::cout << "=============write xml done!";
}
void readCameraParamsXML()
{
	//初始化
	FileStorage fs2("cameraParams.xml", FileStorage::READ);

	第一种方法,对FileNode操作
	//int frameCount = (int)fs2["frameCount"];
	//cout << "frameCount:" << frameCount << endl;

	//std::string date;
	//第二种方法,使用FileNode运算符>>
	//fs2["calibrationDate"] >> date;

	Mat cameraMatrixL, distCoeffL;
	fs2["cameraMatrixL"] >> cameraMatrixL;
	fs2["distCoeffL"] >> distCoeffL;

	Mat cameraMatrixR, distCoeffR;
	fs2["cameraMatrixR"] >> cameraMatrixR;
	fs2["distCoeffR"] >> distCoeffR;

	Mat Rl, Rr, Pl, Pr, T;
	fs2["Rl"] >> Rl;
	fs2["Rr"] >> Rr;
	fs2["Pl"] >> Pl;
	fs2["Pr"] >> Pr;
	fs2["T"] >> T;

	fs2.release();
	printf("read xml done!");
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JoannaJuanCV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值