Skip to content
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 triangulatePoint3 for calibrations with distortion #1128

Merged
merged 3 commits into from
Mar 15, 2022

Conversation

thomassm
Copy link
Contributor

@thomassm thomassm commented Mar 8, 2022

Found what (appears to be) a bug in triangulatePoint3 where it silently uses only the K() component of all Cal3 calibrations even when they have distortion coefficients. To correct:

  • Added tests for triangulation with non-Cal3_S2 calibrations.
  • Added non-zero distortion to the Cal3Bundler test
  • Added skew to the test Cal3_S2 calibration
  • Added an undistortMeasurements step to triangulatePoint3 so that linear triangulation works for calibrations with distortion coefficients.

This seemed like a robust way to solve the problem for all calibration types without breaking anything, but maybe a better solution would be to remove the misleading K() function from distorted calibrations so it doesn't get used by accident and doing different implementations of triangulatePoint3 for different calibrations.

Tests are copy pasted as well, if CppUnitTest has something like gtest's Parameterized Testing I'll fix them to be templated tests.

Prior implementation only used the K() portion of all Cal3 calibrations
for the linear triangulation of points with triangulatePoint3.
- Added tests for triangulation with non-Cal3_S2 calibrations.
- Added skew to the test Cal3_S2 calibration.
- Added an undistortMeasurements step to triangulatePoint3 so that
linear triangulation works for calibrations with distortion
coefficients.
@thomassm thomassm marked this pull request as draft March 9, 2022 09:21
- added undistort for cameras version of triangulatePoint3
- changed to 2 space indent
- changed to calibration from shared calibration
@thomassm thomassm marked this pull request as ready for review March 9, 2022 10:39
Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Something I don't understand right now: it seems you only added code to triangulation.h, so how is the old code broken? And, if it is broken, why is it not modified in this PR?

PS It's been a while I dove deep into triangulation and I have not read the entire header again for this review, so I'm relying on you to jumpstart my memory with this discussion :-)


PinholeCamera<Cal3DS2> camera2Distorted(pose2, *sharedDistortedCal);

// 1. Project two landmarks into two cameras and triangulate
Copy link
Member

Choose a reason for hiding this comment

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

  1. ? Also, please format with Google style...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed the numbering. I ran clang-format --style=Google for the new code, do you have a different formatter though? It made a lot of changes to the original code that I didn't include.

@thomassm
Copy link
Contributor Author

The old code is correct, but only for Cal3_S2, not the other calibrations (or at least not all of them). Since only Cal3_S2 was used in the tests it doesn't show up.

The reason it now works is the added undistortMeasurements step which converts the measurements to be as if they came from a Cal3_S2 model with the same K matrix as the full calibration. So its basically adding a protection layer to use the old code correctly. Hope that is clear!

- new code in triangulation and testTriangulation
- clean up doc number and typos
Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Cool!

Cal3_S2 pinholeCalibration = createPinholeCalibration(cal);
Point2Vector undistortedMeasurements;
// Calibrate with cal and uncalibrate with pinhole version of cal so that measurements are undistorted.
std::transform(measurements.begin(), measurements.end(), std::back_inserter(undistortedMeasurements),
Copy link
Member

Choose a reason for hiding this comment

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

could we just use

for (auto&& measurement: measurements) ?

@dellaert
Copy link
Member

Will merge now, thanks for your contribution!

@dellaert dellaert merged commit 9be5967 into borglab:develop Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants