开发者

How do you read intrinsic and distortion matrixes from file in opencv 2.2

I already have "instinsic.xml" and "distortion.xml" which was produced for my camera. Now I am writing a program using OpenCV 2.2 int开发者_开发百科erface and therefore I am mainly working with cv::Mat data structure as opposed to CvMat. I want to load these two files into corresponding cv::Mat structure. With previous API for OpenCV I would write:

CvMat* intrinsic = (CvMat*) cvLoad("Intrinsics.xml");
CvMat* distortion = (CvMat*) cvLoad("Distortions.xml");

How can I achieve this in OpenCV 2.2? Is there a function that would load the xml file into a cv::Mat for me? I looked all over the API documentation but could not find it.

Thanks,


Something like this should be good for you :

The code is some sort of a sample. There are others in the samples directory of OpenCV which are really relevant and help a lot in these types of manipulations...

//TO WRITE
Mat myMat;
FileStorage fs(filename,FileStorage::WRITE);
fs << "MY_MAT_NAME_IN_THE_XML" << myMat;
fs.release();

//TO READ
Mat myMat;
FileStorage fs(filename,FileStorage::READ);
fs["MY_MAT_NAME_IN_THE_XML"] >> myMat;
fs.release();

I warmly advise you to test the opening with fs.isOpened() aswell, the code could be completed...

For more info, here is the doc

Julien,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜