Camera calibration and conversion to XML file

In order to form a stereo map, I want to get camera calibration information. However, the calibration program in opencv / samples / cpp is difficult for me to write and operate, so I choose to calibrate the camera in MATLAB, but I don’t know how to convert it into opencv readable XML file. If possible, I also want to know for binocular camera extrinsics.yml (XML) and intrinsics.yml (XML) the format of these two files.

Hope to get your help, thank you very much!

unfortunately, we cannot help you with that

here’s how a minimal yml file (for a single camera) would look like:

%YAML:1.0
---
camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 5.3591573396163199e+02, 0., 3.4228315473308373e+02, 0.,
       5.3591573396163199e+02, 2.3557082909788173e+02, 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
   rows: 5
   cols: 1
   dt: d
   data: [ -2.6637260909660682e-01, -3.8588898922304653e-02,
       1.7831947042852964e-03, -2.8122100441115472e-04,
       2.3839153080878486e-01 ]

(complete file here)
(you’re free to change the names (“camera_matrix”, “distortion_coefficients”) to whatever you like)

to read it back, use:

FileStorage fs("my.yml", 0);
Mat cm; fs["camera_matrix"] >> cm; // or whatever name you used before
Mat dc; fs["distortion_coefficients"] >> dc;
fs.release();

Thank you for your reply. I’ll try it further!

btw, opencv’s calibration returns (quite weird) distortion coeffs in the format

r1, r2, p1, p2, r3 

(r rotational, p positional)

Thank you for your reminding. I have completed the intrinsics.yml, However we need R1,R2.P1,P2,Q in extrinsics.yml


Do you know what they stand for?

explained here