Skip to content

This is a correction of the previously missleading documentation and a warning related to a common calibration failure described in issue #15992#15993

Merged
alalek merged 2 commits intoopencv:3.4from
midjji:master
Jan 31, 2020

Conversation

@midjji
Copy link
Copy Markdown
Contributor

@midjji midjji commented Nov 25, 2019

This pullrequest changes

#15992

force_builders=Docs

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Nov 25, 2019

This is a documentation warning regarding a bug which has been around for... well since opencv 2.2 atleast. The bug is difficult to fix in general as a more complicated optimization framework is required to add the required constraints to the solvers. (integer programming, polynomial inequalities. ). The problem is common enough that the documentation actually tries to (incorrectly ) explain away the error. But while its trivial to identify the constraints in the case of only optimizing k1,k2,k3, even identifying the constraints when the additional parameters are added is quite difficult. However, because the problem generally goes away when more photoes with the chessboard spread better over the image, a documentation change seems like a good temporary solution.

@midjji midjji closed this Nov 25, 2019
@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Nov 26, 2019

Mistakenly closed,
opencv calib3d is producing non bijective(not real) lens calibrations. Warning in doc seems like a minimum.

@midjji midjji reopened this Nov 26, 2019
@asmorkalov asmorkalov added category: documentation Documentation fix or update pr: needs rebase Rebase patch (and squash fixup commits) on the top of target branch labels Nov 29, 2019
@asmorkalov
Copy link
Copy Markdown
Contributor

@midjji Please pay attention to CI bot report, the patch contains trailing white spaces: https://pullrequest.opencv.org/buildbot/builders/precommit_docs/builds/22799/steps/whitespace%20opencv/logs/stdio

@asmorkalov
Copy link
Copy Markdown
Contributor

This patch should go into 3.4 branch first. We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

So, please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution.

Please check live results for this patch:

  • use proper formatting for formulas
  • use @note for notes

Note that (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) is always monotonic for real lenses,
and if the estimator produces a non monotonic result, this should be considered a calibration failure.
Note that the result may look deceptively good near the image center but will work poorly in e.g. AR/SFM applications.
The optimization does not include this constraint as the framework does not support the required integer programming and polynomial inequalities. See issue #15992.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See issue #15992

Please use full URL (issue numbers are not handled well in documentation):

Details: https://github.com/opencv/opencv/issues/15992

Comment on lines +121 to +122
The next figures show two common types of radial distortion: barrel distortion
(1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically decreasing) and pincushion distortion (1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically increasing).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catree Could you please take a look on this update? Thank you!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is correct.

Most likely since k1 is an order of magnitude greater than the other terms, it is "sufficient" (or at least this is what can be read elsewhere) to look at the sign of k1 to determine quickly if the distortion is barrel or pincushion?


@midjji

Looking at the equations above, is it not if (1 + k1.r^2 + k2.r^4 + k3.r^6)/(1 + k4.r^2 + k5.r^4 + k6.r^6) (ignoring the tangential distortion coefficients) is monotonically decreasing it produces a barrel distortion? Or it is more complicated when taking into account the denominator?

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Dec 15, 2019 via email

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Dec 16, 2019 via email

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Dec 16, 2019 via email

@asmorkalov
Copy link
Copy Markdown
Contributor

@midjji Have you had a chance to finish the PR? Rebase to 3.4 and some formatting fixes are still required.

@VadimLevin
Copy link
Copy Markdown
Contributor

@midjji Have you had a chance to finish the PR?

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Jan 14, 2020 via email

@midjji midjji changed the base branch from master to 3.4 January 22, 2020 11:16
@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Jan 22, 2020

Assuming my git foo didnt fail I have fixed the issues and rebased to 3.4 according to instructions.

One question, some of this discussion might be a good idea to add to the documentation somewhere. Specifically, tips to get camera calibration right, and how to tell if it went wrong. The existing guides are abysmal.

@asmorkalov asmorkalov removed the pr: needs rebase Rebase patch (and squash fixup commits) on the top of target branch label Jan 22, 2020
@asmorkalov
Copy link
Copy Markdown
Contributor

@alalek @catree could you look at the patch again?


The next figures show two common types of radial distortion: barrel distortion (typically \f$ k_1 < 0 \f$) and pincushion distortion (typically \f$ k_1 > 0 \f$).
The next figures show two common types of radial distortion: barrel distortion
(1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically decreasing)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically decreasing)
(\f$ 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \f$ monotonically decreasing)

The next figures show two common types of radial distortion: barrel distortion (typically \f$ k_1 < 0 \f$) and pincushion distortion (typically \f$ k_1 > 0 \f$).
The next figures show two common types of radial distortion: barrel distortion
(1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically decreasing)
and pincushion distortion (1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically increasing).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and pincushion distortion (1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically increasing).
and pincushion distortion (\f$ 1 + k_1 r^2 + k_2 r^4 + k_3 r^6 \f$ monotonically increasing).

A failed estimation result may look deceptively good near the image center
but will work poorly in e.g. AR/SFM applications.
The optimization does not include these constraints as the framework does not support
the required integer programming and polynomial inequalities. See issue #15992.
Copy link
Copy Markdown
Contributor

@catree catree Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the required integer programming and polynomial inequalities. See issue #15992.
the required integer programming and polynomial inequalities. See [issue 15992](https://github.com/opencv/opencv/issues/15992) for additional information.

More generally, radial distortion must be monotonic and the distortion function, must be bijective.
A failed estimation result may look deceptively good near the image center
but will work poorly in e.g. AR/SFM applications.
The optimization does not include these constraints as the framework does not support
Copy link
Copy Markdown
Contributor

@catree catree Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The optimization does not include these constraints as the framework does not support
The optimization method used in OpenCV camera calibration does not include these constraints as the framework does not support

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@midjji

Regarding the suggestion, there isn't a opt framework in opencv which
supports it, so technically correct as is. Though it's unimportant. Shall I
fix it?

What do you mean? Do you want to change the framework word in the second part of the sentence?
If you feel that the suggestion is not relevant, feel free to ignore it.

At the end, it is just a minor suggestion.

The next figures show two common types of radial distortion: barrel distortion
(1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically decreasing)
and pincushion distortion (1 + k_1 r^2 + k_2 r^4 + k_3 r^6 monotonically increasing).
Radial distortion is always monotonic for real lenses,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pedantic: left align the text to be consistent with the surrounding text.
Maybe too many break lines.

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Jan 23, 2020 via email

@catree
Copy link
Copy Markdown
Contributor

catree commented Jan 24, 2020

Yes, it will complain for trailing whitespace.
Here it is fine. It is just a nitpicking coder comment. It appears like this in an editor:

image

But there will be no effect for documentation rendering.

@asmorkalov
Copy link
Copy Markdown
Contributor

@midjji your turn

@midjji
Copy link
Copy Markdown
Contributor Author

midjji commented Jan 31, 2020 via email

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@midjji Thank you for contribution!
@catree Thanks for review and suggestions!

@alalek alalek merged commit 86e5e8d into opencv:3.4 Jan 31, 2020
@alalek alalek mentioned this pull request Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: documentation Documentation fix or update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants