OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 20 Nov 2013 09:40:03 -0600calibrateCamera - distortion coefficients differ greatlyhttp://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/I'm trying to calibrate the camera of a Blackberry Playbook tablet. To do this I shot several videos of both a *chessboard* and an *asymmetric circles* pattern. I film the pattern from different angles and sides. Using OpenCV, I find a frame that contains the pattern and then I skip a number of frames (equivalent to 0.25-1.0 seconds) for the next input. I use a total of 30 frames. This consistently gives me a reprojection error of about 0.24-0.30, which is reasonable I guess.
My problem is that when I change the amount of frames skipped or the calibration pattern the distortion coefficients change dramatically. I thought it might be caused by motion blur of the camera, but I can't really detect it with my own eyes and I do not move the camera quite gently.
What could I be doing wrong?
----------
Here are some calibration results, taken from output `.yml` files written using `FileStorage`:
distCoeffs: [ 7.8525429419470660e-02, -3.0960261342412626e-01,
-8.6524434042007194e-04, -1.5106802929380169e-03,
2.4943420525237567e-01 ]
reprojectionError: 2.5980283849938213e-01
distCoeffs: [ 9.5072469884162333e-02, -4.0909425759139262e-01,
-1.4098479752338933e-03, -8.5000416228384647e-03,
4.9234810766112463e-01 ]
reprojectionError: 2.9590490979407219e-01
distCoeffs: [ 8.4964364149716379e-02, -2.6207341751103475e-01,
-4.4505493959335414e-04, -5.4369272625535434e-03,
4.7645565934149210e-02 ]
reprojectionError: 2.4693283075662995e-01
distCoeffs: [ -2.4401111960459070e-03, 7.7251179587715735e-01,
-3.4754734701746902e-03, -5.5816510106682163e-03,
-3.8066475946718032e+00 ]
reprojectionError: 2.4246869857561970e-01
I call calibrateCamera a total of 4 times with the following flags (I thought this would increase the accuracy, but the results don't change between calibration passes):
flags = 0;
flags = CALIB_USE_INTRINSIC_GUESS | CALIB_FIX_PRINCIPAL_POINT;
flags = CALIB_USE_INTRINSIC_GUESS | CALIB_FIX_ASPECT_RATIO;
flags = CALIB_USE_INTRINSIC_GUESS;Tue, 19 Nov 2013 10:10:11 -0600http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/Answer by jensenb for <p>I'm trying to calibrate the camera of a Blackberry Playbook tablet. To do this I shot several videos of both a <em>chessboard</em> and an <em>asymmetric circles</em> pattern. I film the pattern from different angles and sides. Using OpenCV, I find a frame that contains the pattern and then I skip a number of frames (equivalent to 0.25-1.0 seconds) for the next input. I use a total of 30 frames. This consistently gives me a reprojection error of about 0.24-0.30, which is reasonable I guess.</p>
<p>My problem is that when I change the amount of frames skipped or the calibration pattern the distortion coefficients change dramatically. I thought it might be caused by motion blur of the camera, but I can't really detect it with my own eyes and I do not move the camera quite gently.</p>
<p>What could I be doing wrong?</p>
<hr>
<p>Here are some calibration results, taken from output <code>.yml</code> files written using <code>FileStorage</code>:</p>
<pre><code>distCoeffs: [ 7.8525429419470660e-02, -3.0960261342412626e-01,
-8.6524434042007194e-04, -1.5106802929380169e-03,
2.4943420525237567e-01 ]
reprojectionError: 2.5980283849938213e-01
distCoeffs: [ 9.5072469884162333e-02, -4.0909425759139262e-01,
-1.4098479752338933e-03, -8.5000416228384647e-03,
4.9234810766112463e-01 ]
reprojectionError: 2.9590490979407219e-01
distCoeffs: [ 8.4964364149716379e-02, -2.6207341751103475e-01,
-4.4505493959335414e-04, -5.4369272625535434e-03,
4.7645565934149210e-02 ]
reprojectionError: 2.4693283075662995e-01
distCoeffs: [ -2.4401111960459070e-03, 7.7251179587715735e-01,
-3.4754734701746902e-03, -5.5816510106682163e-03,
-3.8066475946718032e+00 ]
reprojectionError: 2.4246869857561970e-01
</code></pre>
<p>I call calibrateCamera a total of 4 times with the following flags (I thought this would increase the accuracy, but the results don't change between calibration passes):</p>
<pre><code>flags = 0;
flags = CALIB_USE_INTRINSIC_GUESS | CALIB_FIX_PRINCIPAL_POINT;
flags = CALIB_USE_INTRINSIC_GUESS | CALIB_FIX_ASPECT_RATIO;
flags = CALIB_USE_INTRINSIC_GUESS;
</code></pre>
http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?answer=24135#post-id-24135Camera distortion estimation, and calibration for that matter, involves solving high dimensional non linear minimization problem that is quite sensitive to the input data. Looking at your values, I would say that they vary within a reasonable margin. In your case the radial distortion model with higher order coefficients, here you have coefficients for the r^2, r^4 and r^6 terms, is an overparametrization for the distortion of your lens. Because you can achieve similar reprojection errors with distortion parameters varying by up to an order of magnitude strongly indicates this model has too many degrees of freedom.
In general I would not worry too much about varying distortion and calibration parameters as long as the rectified image does not have visible distortion and the reprojection error remains low.Tue, 19 Nov 2013 11:22:25 -0600http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?answer=24135#post-id-24135Comment by jensenb for <p>Camera distortion estimation, and calibration for that matter, involves solving high dimensional non linear minimization problem that is quite sensitive to the input data. Looking at your values, I would say that they vary within a reasonable margin. In your case the radial distortion model with higher order coefficients, here you have coefficients for the r^2, r^4 and r^6 terms, is an overparametrization for the distortion of your lens. Because you can achieve similar reprojection errors with distortion parameters varying by up to an order of magnitude strongly indicates this model has too many degrees of freedom.</p>
<p>In general I would not worry too much about varying distortion and calibration parameters as long as the rectified image does not have visible distortion and the reprojection error remains low.</p>
http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24210#post-id-24210The classical check for distortion is to look at straight lines in your scene (so along the checkerboard pattern), and check that they are straight in your image. The most distortion is likely occur around the four corners of your image.Wed, 20 Nov 2013 09:40:03 -0600http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24210#post-id-24210Comment by Marin for <p>Camera distortion estimation, and calibration for that matter, involves solving high dimensional non linear minimization problem that is quite sensitive to the input data. Looking at your values, I would say that they vary within a reasonable margin. In your case the radial distortion model with higher order coefficients, here you have coefficients for the r^2, r^4 and r^6 terms, is an overparametrization for the distortion of your lens. Because you can achieve similar reprojection errors with distortion parameters varying by up to an order of magnitude strongly indicates this model has too many degrees of freedom.</p>
<p>In general I would not worry too much about varying distortion and calibration parameters as long as the rectified image does not have visible distortion and the reprojection error remains low.</p>
http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24138#post-id-24138That's good to hear. I'll do some extra testing to see if the rectified image is indeed correct and accept your answer if that is the case. Thanks!Tue, 19 Nov 2013 12:33:23 -0600http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24138#post-id-24138Comment by Marin for <p>Camera distortion estimation, and calibration for that matter, involves solving high dimensional non linear minimization problem that is quite sensitive to the input data. Looking at your values, I would say that they vary within a reasonable margin. In your case the radial distortion model with higher order coefficients, here you have coefficients for the r^2, r^4 and r^6 terms, is an overparametrization for the distortion of your lens. Because you can achieve similar reprojection errors with distortion parameters varying by up to an order of magnitude strongly indicates this model has too many degrees of freedom.</p>
<p>In general I would not worry too much about varying distortion and calibration parameters as long as the rectified image does not have visible distortion and the reprojection error remains low.</p>
http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24165#post-id-24165I cannot really see a difference in the undistorted output whether I use one calibration result or the other, so you were right!Wed, 20 Nov 2013 03:16:17 -0600http://answers.opencv.org/question/24132/calibratecamera-distortion-coefficients-differ-greatly/?comment=24165#post-id-24165