Matlab摄像头标定得出的参数保存为xml

   最近在做双摄像头的立体匹配,发现OpenCV定标效果不如MatLab的效果,于是用MatLab标定箱做标定,将得到的结果保存为xml,然后,提供给opencv使用。

   MatLab标定箱做标定得到的结果如下图所示:

   

   将结果保存为xml代码如下:

  

// SaveMatLabCalibParam.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <cv.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
	double data[9]={ 497.16547, 0 , 192.57159, 
		0 , 496.12240, 110.37805,
		0 , 0, 1
	};

	CvMat intrinsic_matrix;

	cvInitMatHeader(&intrinsic_matrix,3,3,CV_64F,data);

	cvSave("intrinsic.xml",&intrinsic_matrix);

	return 0;
}
得到的xml内容如下:


注意:关于MatLab标定箱得到的旋转向量R矩阵为1X3,如何转换为opencv需要的3X3向量?

你LoadXML之后,通过cvRodrigues2转换为3X3即可。代码如下:

CvMat *pTemp = (CvMat *)cvLoad("roation.xml");
CvMat *pDst = cvCreateMat(3,3,CV_64FC1);
cvRodrigues2(pTemp, pDst);



猜你喜欢

转载自blog.csdn.net/ily6418031hwm/article/details/14533013