-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cal3 fisheye jacobian #902
Merged
varunagrawal
merged 16 commits into
borglab:develop
from
roderick-koehle:Fix-Cal3Fisheye-Jacobian
Nov 28, 2021
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d9c770d
Forward declaration of PinholeCameraCal3Fisheye
roderick-koehle ab92ba7
Merge pull request #3 from roderick-koehle/patch-1
roderick-koehle 9440ff6
Merge branch 'borglab:develop' into develop
roderick-koehle 0a1fead
Test of jacobian of Cal3Fisheye for on-axis point
roderick-koehle 1640f17
Test jacobian of Cal3Unified for on-axis point
roderick-koehle 8df2c70
Avoid division by zero in jacobian calculation
roderick-koehle f844481
Merge branch 'borglab:develop' into Fix-Cal3Fisheye-Jacobian
roderick-koehle 91103d5
Check numeric stability close to optical axis
roderick-koehle c0219c1
Numerically stable refactoring of fisheye jacobian
roderick-koehle 0d01e48
Fix missing semicolons
roderick-koehle 8c2ea78
Undo change in scaling function
roderick-koehle e1db2be
Fix type in extression for dyd_dyi
roderick-koehle 2763bd8
Convergence of equidistant scaling utilizing atan2
roderick-koehle 296c937
Fix calling scaling_factor static method.
roderick-koehle 8a6b2aa
Removed comments
roderick-koehle 8846324
Merge branch 'borglab:develop' into Fix-Cal3Fisheye-Jacobian
roderick-koehle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be
r2 < 1e-7
or some other tolerance.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
r2>0
implies the resolution of the image radius r to be abovesqrt(std::numeric_limits<double>::denorm_min())
~ 1.49e-154. By avoiding to compute the square or divisor of two small values, the resulting gradient should be reasonably accurate.I implemented a python testcase
test_jacobian_convergence
intest_Cal3Fisheye.py
to cover this situation.In the current implementation of the jacobian, this results in a overflow or division by zero error, if the square radius r2 is of the size of 1 ulp (unit of least precision in C++ std::numeric_limits::denorm_min() ~ 4.94e-324).
I suggest the refactoring in provided patch below, avoiding the offending division by 1/r2 (or multiplication with rrdiv).
Eventually, the interface design might be extended supporting incident angles above 90 deg. It may be beneficial to generalize the formulation of derivatives, to cover the case zi != 1. The scaling function needs to be generalized to use atan2(r, z)/r instead of atan(r)/r. From numeric tests, is seems fine to implement the scaling for (r/z != 0). See the
test_scaling_factor
unit test to cover this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roderick-koehle I believe @ProfFan was referring to the fact that doing a
r2==0
check is numerically unstable since that check will fail forr2=1e-15
but the value of r2 in this case is still small enough to cause various issues like overflow and bad jacobians.This is a recommendation for doing a numerical check rather than an algebraic check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply.
An arbitrary fixed threshold to select the paraxial approximation I would not recommend.
The critical numerically unstable calculation is the calculation of the unit directions.
c, s = x/r, y/r
this problem is related to computing the givens rotation, e.g. used in the blas library.
Once the unit direction is known, the sine and cosine will be a normalised number and no overflow/underflow issues can occur.
For a more in depth discussion about the issues, see:
Bindel, Demmel, Kahan, "On Computing Givens Rotations Reliably and Efficiently"
The current suggested implementation is simple and numerically stable, this is demonstrated and covered by the provided python tests. In this case, using
(r2==0)
is a well defined lower threshold imposed onr2
being independent of the floating point datatype being used.Alternatively, for using a higher threshold, e.g. for
1/3 r2 < 0.5 eps
with eps being the machine precision, the distortion induced by thearctan(xi)/xi ~ 1+1/3 x^2
becomes equal to one and the paraxial approximation can be used. For this choice, k1 should not exceed 1/3 (the fist taylor coefficient of the tan series development) andz
is assumed 1. See the boost sinc_pi implementation to illustrate this technique. Note the discussion, https://stackoverflow.com/questions/47215765/is-boostmathsinc-pi-unnecessarily-complicatedabout using taylor bounds.
My suggestion is to either stay with the simple type-independent scheme using the condition
r2==0
, or compute the direction cosines using a stable unit direction implementation, similar to the givens rotation implementation as proposed by the publication by Blink. Then, no paraxial case is necessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay this makes sense. Thanks for the explanation.
Can you please address the other comments as well?