You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calibrateCamera does not enforce lens model constraints #15992
calibrateCamera using k1, k2, k3 should enforce that k1r^2 + k2r^4 +k3*r^6 must be either monotonically increasing or monotonically decreasing as this is a constraint of real lens, or atleast all real lenses for which this (Brown) lens model is used. A marginally harder constraint which could be used instead is that they should all have the same sign.
Current state: this not enforced by the optimizer.
The most common case during which this constraint is violated in practice is when the chessboard observations are not well spread in the image. Note that this is the source of many a failed calibration. The ring pattern, or reflections, which it creates near the edges of the sampled pixels will be familiar to many when the full space where there are pixels are computed as undistortion. In particular this type of failure will fool most people as the reprojection error will be low, and the undistortion will appear reasonable in the center of the image.
Because the optimizer does not support mixed integer inequality constraints, and because such an optimizer will not fix the problem of the poor sampling anyways I propose to add a notice to the calibrateCamera docs which describes the problem. pull requiest incoming.
Note that this problem is so common that the opencv documentation explicity states that k>0 is (typically) barrel distortion. (This comment is explicitly there because people thought failed calibrations where actually successful and wrote the error into the documentation.)
Note there are several more unfullfilled constraints on k4:6 and tangential parameters. The discussion above assumes they are set to zero. Otherwize these more complicated constraints must be fullfilled aswell.
Ideally, an example image of the produced "artifact" should be added.
If it is feasible easily, why not add a check at the end of the calibration.cpp sample so as to warn the user when the estimated parameters could produce this kind of issue?
Also, a more general update, improvement of the camera calibration tutorials should be considered:
Camera calibrate can(theoretically) always produce this kind of error, regardless of how well you perform the calibration, but its less likely if you do it well.
Yes, thats a fairly typical example, but there are other variants which are more subtle, a single sharp ring distortion at one position e.g.
If and only if your distortion model only contains the k1:3 and they are monotone, this type of distortion/error does not occur, the real criteria is that lenses are bijective for rays, which can fail to be fullfilled if you have a combination of e.g. k4:6 or tangential etc. The full function beeing monotonic along each r is necc and sufficient though. (havent looked at the s parameters, but odds are they should never be used anyways)
The most common error people make is holding, either the calibration pattern or the camera, by hand. Meaning it moves while you capture the image. Motion blur causes critical failure, depth of field blur is less of a problem in most cases, and if it is a big problem, you need a different camera model.
Having poor lighting conditions(office lighting) is another, which worsens the above.
The second most common error is to use more parameters than you should, most use 4+8 params because its default. but if your lense is symetric(it is, or toss it) and your pixels square(it is, or you got something very rare which is mentioned in its docs), then fx==fy, minor deviation is just that the optimal parameter set will not minimize the observation error, large deviation is more likely to be calibration failure than assymetric lense or uneven sensor pixels. Similarily, tangential distortion most likely means your camera sensor is improperly mounted or lose, meaning if you actually have this, shake the camera, calibrate again, and see if it changed, if it did, toss the camera. Finally, use e.g. akikake information or something similar to determine which of the k_i you should use, odds are k1, k2 are sufficient.
Both work fine, the circle patterns can be slightly more robust/easier to use when chessboard does not work, but gives lower final accuracy, but there are line/gradient based methods which give an order or two of magnitude of improvment. There are no good commercial or opensource implementations of the latter though, and they are a pain in the ass to use in practice.
I have no intention of writing a guide, but I dont want the opencv doc to try and hide the problem as it has been.
Reacted by giladosk
Reacted by Samuel Bryner, Nuno Alexandre, Hugo MIRANDA QUEIROS, Jurriaan Barkey Wolf and Manuel
I think I will open another thread for suggestions about camera calibration tutorial improvement. I put here some information I found interesting and that could help other people.
Possible issue with circle grid pattern in the OpenCV implementation is that it seems it does not take into account the perspective bias when locating the circle/ellipse centroid, #7312
there are line/gradient based methods which give an order or two of magnitude of improvment.
Feel free to add references.
Are there some good references about the camera calibration process? From the pure theoretical point of view, I guess that the Zhang's paper or Heikkila one are good references.
Some new approaches to guide the user during the camera calibration process:
This has some really good ideas, with qualifications. The most important
result is this:
In the calibrated sfm case, always use their central method first i.e as
default.
Though if you want a super easy calibration with bare minimum accuracy use
a one param radial model instead.
The second most important caveat is this: their methods are useless for the
collection of uncalibrated images sfm. And collecting calibration images is
much more work, the paper does not cover balanced sampling, but it's
probably very important. Though as always sattlers brand of careful detail
is appreciated.
I recommend opencv implement a wrapper for the end result( project and
unproject) of at least the central model, but not that you implement the
full method, simply refer their repo. Which is what I'll be doing next
week in my sfm pipeline before recalibrating -_-'... Damn, I really should
have thought of this.
I have been dealing with this problem in practice quite a lot recently, with many perfect calibration snapshots and "bad" distortion results after the calibration, especially near the corners - the farthest points from the optical axis. Now I can see I am not the only one.
The requirement of the distortion transformation being bijective sounds reasonable and quite general. As I understand, when the distortion transformation is not bijective, its Jacobian becomes zero, and we start seeing the mentioned reflection effects, etc. The distortion Jacobian is not difficult to express analytically from the distortion formulae. Would it be an idea to constrain the optimization algorithm with a condition of non-zero Jacobian within the image dimension domain? Maybe someone has already tried that?
It's not quite that simple.
1/p(X) where p(X) has roots does not give zero Jacobians near the roots, it
gives inf/undefined Jacobians. In general opencv would need a general no
opt framework that supports boundaries. But such frameworks basically still
don't work for real problems consistently unless you initialized well for
well conditioned data. But if you have that the current solution works too.
The simplest solution is to remove degrees of freedom you do not need. If
you get the problem, either they were not there or you initialized
poorly,(pattern detected upside down is common).
A practical solution is to hold the camera and pattern still. IE not by
human hands. Then take enough images to cover the image space evenly,
including all corners. Around 60 images detection checked images with mild
inclinations and a good distribution generally works well. At least for the
lower order models.
An alternative if you really need both model count and data is to
reparametrize in terms of positive real roots estimated as squares of
parameters.
This kind of model is also mostly the quick and dirty kind, a better
solution is a regularizes nurb surface or something like what's in the 10k
parameters are better than 12.
On Tue, 29 Dec 2020, 22:53 Vladimir Fedorov, ***@***.***> wrote:
I have been dealing with this problem in practice quite a lot recently,
with many perfect calibration snapshots and "bad" distortion results after
the calibration, especially near the corners - the farthest points from the
optical axis. Now I can see I am not the only one.
The requirement of the distortion transformation being bijective sounds
reasonable and quite general. As I understand, when the distortion
transformation is not bijective, its Jacobian becomes zero, and we start
seeing the mentioned reflection effects, etc. The distortion Jacobian is
not difficult to express analytically from the distortion formulae. Would
it be an idea to constrain the optimization algorithm with a condition of
non-zero Jacobian within the image dimension domain? Maybe someone has
already tried that?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#15992 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJQYJPRDXNMNK6JRZDA5N3SXJFXBANCNFSM4JROAR2A>
.
Activity
catree commentedon Dec 15, 2019
If I understand correctly, when the calibration procedure is done "badly", this can produce this kind of undistortion images?
https://answers.opencv.org/question/28438/undistortion-at-far-edges-of-image/

https://robotics.stackexchange.com/questions/11106/stereo-camera-calibration-with-different-camera-types
https://stackoverflow.com/questions/46100927/python-2-7-opencv-3-3-error-in-cv2-initundistortrectifymap-not-showing-undist
...
Mathematically speaking, this can be checked by verifying that the estimated
k1r^2 + k2r^4 + k3*r^6function is monotone?Since it is a common error, ideally a note/warning should be added wherever the camera calibration topic appears in the doc:
Ideally, an example image of the produced "artifact" should be added.
If it is feasible easily, why not add a check at the end of the calibration.cpp sample so as to warn the user when the estimated parameters could produce this kind of issue?
Also, a more general update, improvement of the camera calibration tutorials should be considered:
A set of guidelines for correct camera calibration would be very useful.
So far, common source of errors I believe are encountered by beginners:
So what camera calibration procedure should be adopted? So far I have found the following information:
Or some advice similar to:
Also, which calibration pattern should be preferred between the asymmetric chessboard and the asymmetric circle grid pattern?
Related #14596
midjji commentedon Dec 16, 2019
Camera calibrate can(theoretically) always produce this kind of error, regardless of how well you perform the calibration, but its less likely if you do it well.
Yes, thats a fairly typical example, but there are other variants which are more subtle, a single sharp ring distortion at one position e.g.
If and only if your distortion model only contains the k1:3 and they are monotone, this type of distortion/error does not occur, the real criteria is that lenses are bijective for rays, which can fail to be fullfilled if you have a combination of e.g. k4:6 or tangential etc. The full function beeing monotonic along each r is necc and sufficient though. (havent looked at the s parameters, but odds are they should never be used anyways)
The most common error people make is holding, either the calibration pattern or the camera, by hand. Meaning it moves while you capture the image. Motion blur causes critical failure, depth of field blur is less of a problem in most cases, and if it is a big problem, you need a different camera model.
Having poor lighting conditions(office lighting) is another, which worsens the above.
The second most common error is to use more parameters than you should, most use 4+8 params because its default. but if your lense is symetric(it is, or toss it) and your pixels square(it is, or you got something very rare which is mentioned in its docs), then fx==fy, minor deviation is just that the optimal parameter set will not minimize the observation error, large deviation is more likely to be calibration failure than assymetric lense or uneven sensor pixels. Similarily, tangential distortion most likely means your camera sensor is improperly mounted or lose, meaning if you actually have this, shake the camera, calibrate again, and see if it changed, if it did, toss the camera. Finally, use e.g. akikake information or something similar to determine which of the k_i you should use, odds are k1, k2 are sufficient.
Both work fine, the circle patterns can be slightly more robust/easier to use when chessboard does not work, but gives lower final accuracy, but there are line/gradient based methods which give an order or two of magnitude of improvment. There are no good commercial or opensource implementations of the latter though, and they are a pain in the ass to use in practice.
I have no intention of writing a guide, but I dont want the opencv doc to try and hide the problem as it has been.
catree commentedon Dec 19, 2019
Thanks for the valuable information.
I think I will open another thread for suggestions about camera calibration tutorial improvement. I put here some information I found interesting and that could help other people.
Possible issue with circle grid pattern in the OpenCV implementation is that it seems it does not take into account the perspective bias when locating the circle/ellipse centroid, #7312
On a related topic: #15577
Typo, I don't know the method but I think it should be Akaike information criterion
Feel free to add references.
Are there some good references about the camera calibration process? From the pure theoretical point of view, I guess that the Zhang's paper or Heikkila one are good references.
Some new approaches to guide the user during the camera calibration process:
catree commentedon Mar 29, 2020
Found this repository Accurate geometric camera calibration:
After founding this repository, Bundle Adjusted Direct RGB-D SLAM:
midjji commentedon Mar 29, 2020
VladimirVLF commentedon Dec 29, 2020
I have been dealing with this problem in practice quite a lot recently, with many perfect calibration snapshots and "bad" distortion results after the calibration, especially near the corners - the farthest points from the optical axis. Now I can see I am not the only one.
The requirement of the distortion transformation being bijective sounds reasonable and quite general. As I understand, when the distortion transformation is not bijective, its Jacobian becomes zero, and we start seeing the mentioned reflection effects, etc. The distortion Jacobian is not difficult to express analytically from the distortion formulae. Would it be an idea to constrain the optimization algorithm with a condition of non-zero Jacobian within the image dimension domain? Maybe someone has already tried that?
midjji commentedon Dec 30, 2020