#include "opencv2/opencv.hpp" <p>using namespace cv; </p>FileStorage camcalibrate("camcalibrate.xml",FileStorage::WRITE); cv::Mat cameraMatrix= cameraCalibrator.getCameraMatrix(); cv::Mat DistCoeffsMatrix= cameraCalibrator.getDistCoeffs(); camcalibrate<< "cameraMatrix" << cameraMatrix << "distCoeffs" << DistCoeffsMatrix.t(); camcalibrate.release(); cv::waitKey();
文件结果如下:
<?xml version="1.0"?> <opencv_storage> <read>"camera calibration by kint at 05.02.03"</read> <imageCount>12</imageCount> <cameraMatrix type_id="opencv-matrix"> <rows>3</rows> <cols>3</cols> <dt>d</dt> <data> 5.0519443370436323e+02 0. 3.2083884160474554e+02 0. 5.0285768483869174e+02 2.3831697216475899e+02 0. 0. 1.</data></cameraMatrix> <distCoeffs type_id="opencv-matrix"> <rows>5</rows> <cols>1</cols> <dt>d</dt> <data> -9.2216292456289706e-02 6.5000304572855785e-02 -6.3123997885573520e-04 3.2158869444328347e-03 5.7265487017375147e-02</data></distCoeffs> </opencv_storage>
2. 过程中出现的问题:
1)FileStorage的作用域:
using namespace cv; 或 cv::FileStorage camcalibrate("camcalibrate.xml",cv::FileStorage::WRITE);//后一个容易忽略
2) FileStorage 的camcalibrate.xml 文件中未保存有数据。
camcalibrate.release(); 要有。。 //cv::waitKey(); 在之前先关闭 FileStorage 文件
详细参考:
http://blog.csdn.net/yang_xian521/article/details/6897684
http://blog.csdn.net/mmjwung/article/details/6913540
http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html
原文链接:https://www.f2er.com/xml/297248.html