void writeCameraParamsXML()
{
FileStorage fs("cameraParams.xml", FileStorage::WRITE);
//开始文件写入
fs << "frameCount" << 20;
time_t rawtime;
time(&rawtime);
fs << "calibrationDate" << asctime(localtime(&rawtime));
Mat cameraMatrixL = (Mat_(3, 3) << 269.7783887712764, 0, 151.0565879797926,
0, 267.0670770707237, 103.2889641857869,
0, 0, 1);
Mat distCoeffL = (Mat_(5, 1) << 3.292753725003047e-05,
0.3334558546209874,
-0.0007762980542583555,
0.002768478869536125,
-1.022355978205538);
Mat cameraMatrixR = (Mat_(3, 3) << 269.1356478541644, 0, 158.509582761769,
0, 266.4233661647525, 122.2878154003198,
0, 0, 1);
Mat distCoeffR = (Mat_(5, 1) << -0.002516093790587057,
0.5080801263588319,
0.00159686792699245,
0.00447049258279624,
-1.911823270199251);
Mat Rl = (Mat_(3, 3) << 0.9990638869827868, -0.01888052892505704, 0.0389213996967679,
0.0141542003027198, 0.9928750152118871, 0.1183167899403338,
-0.04087796889078475, -0.1176551307657455, 0.9922128107739082);
Mat Rr = (Mat_(3, 3) << 0.9991055369603488, -0.01260449834282734, -0.04036400174287882,
0.01498925630502581, 0.998125615280672, 0.05933446145371164,
0.03954046295373517, -0.0598864153385842, 0.9974217608651312);
Mat Pl = (Mat_(3, 4) << 268.7616960851367, 0, 124.6051635742188, 0,
0, 268.7616960851367, 97.82008457183838,
0, 0, 0, 1, 0);
Mat Pr = (Mat_(3, 4) << 268.7616960851367, 0, 124.6051635742188, 0,
0, 268.7616960851367, 97.82008457183838, 8326.861924888874,
0, 0, 1, 0);
Mat T = (Mat_(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!");
}