0
votes

I am currently working to calibrate a camera and I tried using both the Caltech Camera Calibration Toolbox for Matlab and OpenCV. I used the same images for both methods. Even if the error seems to be more or less the same between the two methods, the values don't quite match, especially the distortion coefficients

Matlab results

Calibration results after optimization (with uncertainties):

Focal Length:          fc = [ 1475.06776   1474.34956 ] +/- [ 1.30130   1.28283 ]
Principal point:       cc = [ 967.66660   535.09387 ] +/- [ 1.44019   1.23663 ]
Skew:             alpha_c = [ 0.00000 ] +/- [ 0.00000  ]   => angle of pixel axes = 90.00000 +/- 0.00000 degrees
Distortion:            kc = [ 0.06844   -0.15582   0.00049   0.00021  0.00000 ] +/- [ 0.00235   0.00641   0.00028   0.00035  0.00000 ]
Pixel error:          err = [ 0.64754   0.45951 ]

Note: The numerical errors are approximately three times the standard deviations (for reference).

and OpenCV results

RMS:  0.40118611304523083
Camera matrix:  [[1.46405121e+03 0.00000000e+00 9.64151487e+02]
 [0.00000000e+00 1.46362963e+03 5.35514933e+02]
 [0.00000000e+00 0.00000000e+00 1.00000000e+00]]
Distortion coefficients:  [[ 2.27565390e-01 -1.22470407e+00  3.58771830e-04 -4.77602117e-04
   1.96274452e+00]]

I understand that there are differences between the two methods (e.g. corner extraction method) so I shouldn't expect exactly the same results, but the difference still looks significant to me. I tried taking more images of my chessboard tilted at different angles, but the values and the errors don't vary that much.

I am mostly surprised by the difference in the distortion coefficients, as they have orders of difference. If I undistort the chessboard images using the values from the two calibrations, they both look reasonable even if the OpenCV one shows more barrell correction.

Undistorted using Matlab calibration Undistorted using Matlab calibration

Undistorted using OpenCV calibration Undistorted using OpenCV calibration

My guess is that since the camera does not have too much distortion to start with the two methods converge to different solutions. My question is, is there a way to determine which of these two calibration gives the "best" result? Would they be both acceptable even if they are clearly different?

OpenCV seems to be worse, the lines on the chessboard corners/borders are less straight. Line straightness is a good metric to measure the quality of the undistortion. Do you know the algorithm used by matlab? If it uses less distortion coefficients, you can limit them in opencv as well. Can you view and compare the detected chessboard corners? - Micka
your data doesn't reach into the corners, where distortion is worst, and the numerical optimization has no support there, which is why it's giving you solutions that fluctuate wildly in the corners. tldr: get data that covers the whole picture. - Christoph Rackwitz