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

feat(intrinsic_camera_calibrator): multiple camera models & ceres integration #208

Open
wants to merge 33 commits into
base: tier4/universe
Choose a base branch
from

Conversation

amadeuszsz
Copy link
Contributor

@amadeuszsz amadeuszsz commented Nov 6, 2024

Description

Related links

Tests performed

Notes for reviewers

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

  • The PR follows the pull request guidelines.
  • The PR has been properly tested.
  • The PR has been reviewed by the code owners.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.
  • The PR is ready for merge.

After all checkboxes are checked, anyone who has write access can merge the PR.

…ls & ceres integration

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@amadeuszsz amadeuszsz self-assigned this Nov 6, 2024
pre-commit-ci bot and others added 5 commits November 6, 2024 08:24
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
…ation settings

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 104 lines in your changes missing coverage. Please review.

Project coverage is 0.27%. Comparing base (bab5400) to head (774dd90).
Report is 27 commits behind head on tier4/universe.

Files with missing lines Patch % Lines
...rinsic_camera_calibrator/coefficients_residual.hpp 0.00% 60 Missing ⚠️
...r/intrinsic_camera_calibrator/camera_calibrator.py 0.00% 17 Missing ⚠️
...alibrator/intrinsic_camera_calibrator/parameter.py 0.00% 7 Missing ⚠️
...ra_calibrator/intrinsic_camera_calibrator/utils.py 0.00% 6 Missing ⚠️
...librator/src/ceres_camera_intrinsics_optimizer.cpp 0.00% 5 Missing ⚠️
...tor/ceres_intrinsic_camera_calibrator/src/main.cpp 0.00% 4 Missing ⚠️
...rator/src/ceres_intrinsic_camera_calibrator_py.cpp 0.00% 3 Missing ⚠️
...ator/intrinsic_camera_calibrator/data_collector.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           tier4/universe    #208      +/-   ##
=================================================
- Coverage            0.93%   0.27%   -0.67%     
=================================================
  Files                 270      30     -240     
  Lines               21339    2535   -18804     
  Branches              383     263     -120     
=================================================
- Hits                  200       7     -193     
+ Misses              20982    2528   -18454     
+ Partials              157       0     -157     
Flag Coverage Δ
differential 0.27% <0.00%> (?)
total ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…calibration for Ceres

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@amadeuszsz amadeuszsz marked this pull request as ready for review November 13, 2024 06:04
@amadeuszsz amadeuszsz added the enhancement New feature or request label Nov 13, 2024
… Ceres

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@knzo25
Copy link
Collaborator

knzo25 commented Nov 18, 2024

@amadeuszsz
remember to link the related tickets and data needed to reproduce (so I can use the same data and independent one if possible)

@knzo25
Copy link
Collaborator

knzo25 commented Nov 18, 2024

@amadeuszsz
Regarding:
intrinsic_camera_calibrator/intrinsic_camera_calibrator/intrinsic_camera_calibrator/board_detections/board_detection.py,

The several statistics related to the pose, angles, etc that require a camera model, should use "the best camera model available", which is not the single shot. Single shot works well for these only in the case that the camera is not distorted.

Single shot should be used to detect outliers based on the reprojection error. E.g., if a model can not fit even one sample, it is highly probable that that sample is an outlier

Copy link
Collaborator

@knzo25 knzo25 left a comment

Choose a reason for hiding this comment

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

@amadeuszsz
Confirmed basic functionalities, but got enough comments that I feel I would like to see them addressed or dicussed before further reviews

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
…ht for distortion coefficients via loss function

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@amadeuszsz
Copy link
Contributor Author

amadeuszsz commented Nov 19, 2024

remember to link the related tickets and data needed to reproduce (so I can use the same data and independent one if possible)

@knzo25
The most important / unique data is for regularization, which isolates unstable coefficients issue. It was attached in this ticket INTERNAL LINK
Also updated link for all the data used in experiments in this ticket INTERNAL LINK

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@knzo25
Copy link
Collaborator

knzo25 commented Nov 20, 2024

@amadeuszsz
Regarding my previous comment:

@amadeuszsz
Regarding:
intrinsic_camera_calibrator/intrinsic_camera_calibrator/intrinsic_camera_calibrator/board_detections/board_detection.py,

The several statistics related to the pose, angles, etc that require a camera model, should use "the best camera model available", which is not the single shot. Single shot works well for these only in the case that the camera is not distorted.

Single shot should be used to detect outliers based on the reprojection error. E.g., if a model can not fit even one sample, it is highly probable that that sample is an outlier

This may be too big for this PR since also affects some of sergio's work. In the meantime, can you turn all data collection filters that use 3D information ? (pose, 3d rotation, etc). As explained before, using single shot models to estimate these values with highly distorted cameras will end up with trashy values

use_tangential_distortion=self.use_tangential_distortion,
)

# Consider only part of data (distributed uniformly)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this assumption valid? (I do not remember implementing shuffling 🤔 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For initial calibration I assume it is better to take uniform distributed (from collecting sequence point of view) samples, e.g. If we have 80 samples and 40 samples limit for initial calibration, we take 1, 3, 5... instead of 1-40. We could take samples base on pose distribution as well, but I didn't find it necessary.
In general, I would prefer to remove this limit in favor of timeout parameter, but OpenCV API does not consider this. Separate thread for init calibration task would not work - breaking it will not result with recent intrinsic parameters. Maybe calibrating frame by frame here is an answer, but I doubt the performance.

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
and model == self._cached_camera_model
and self._cached_reprojection_errors is not None
):
if self._cached_camera_model is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if we do not apply the full behavior regarding the 3d statistics that require a non-single shot calibration, the following should still be implemented in this PR:

Have:
get_reprojection_errors: uses an existing model
and
get_single_shot_reprojection_errors: forces calibration using a single sample. It still requires an input model to know which kind of model it should use (parameters ,etc)

Alternatively, use only get_reprojection_errors and implement the required behavior in the caller.

Currently, there are two kind of uses for self._cached_camera_model. Maybe the should be split.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this method, what happens if:
self._cached_camera_model is not None and model != self._cached_camera_model ?

Copy link
Contributor Author

@amadeuszsz amadeuszsz Nov 20, 2024

Choose a reason for hiding this comment

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

get_reprojection_errors: uses an existing model

Using existing model seems working here after changes in camera model (using last camera matrix & coefficients), but after triggering calibration we obtain bad results. There are some assumptions in _calibrate within calibrator and mentioned change in camera model is breaking change. I would need to reconsider design here again.

Instead of refactor twice, I would prefer to address this issue with this at once in separate PR if it is not a problem.

In this method, what happens if:
self._cached_camera_model is not None and model != self._cached_camera_model ?

Model has been changed, so we want to update our reprojection error. Isn't it expected behavior? We can change it.

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
height = detections[0].get_image_height()
width = detections[0].get_image_width()

camera_model = CameraModel()
camera_model = make_camera_model(camera_model_type=CameraModelEnum.OPENCV)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems to be a problem from before, but can you check if all .value accesses are done in a locked context?
Applies to the calibration related methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just checked it and it seems .value for all parameters from GUI are reflected here.

@knzo25
Copy link
Collaborator

knzo25 commented Nov 20, 2024

@amadeuszsz
Regarding how the distortion coefficients are treated inside the ceres calibrator.
Kind of got the impression there would be errors if radial coefficients < 3 and rational cofficients > 0.
Could you check? If seems to much a trouble, we could add a restriction that makes radial coefficients == 3 if we want to use rational coefficients (personally, I would prefer this 😅 )

Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
Signed-off-by: amadeuszsz <amadeusz.szymko.2@tier4.jp>
@amadeuszsz
Copy link
Contributor Author

@knzo25

Regarding how the distortion coefficients are treated inside the ceres calibrator. Kind of got the impression there would be errors if radial coefficients < 3 and rational cofficients > 0. Could you check? If seems to much a trouble, we could add a restriction that makes radial coefficients == 3 if we want to use rational coefficients (personally, I would prefer this 😅 )

Why? I checked and it works for any combination. Also I can see how reprojection error changes so I believe it is due to camera model configuration.

Regarding:

intrinsic_camera_calibrator/intrinsic_camera_calibrator/intrinsic_camera_calibrator/board_detections/board_detection.py,

The several statistics related to the pose, angles, etc that require a camera model, should use "the best camera model available", which is not the single shot. Single shot works well for these only in the case that the camera is not distorted.

Single shot should be used to detect outliers based on the reprojection error. E.g., if a model can not fit even one sample, it is highly probable that that sample is an outlier

This may be too big for this PR since also affects some of sergio's work. In the meantime, can you turn all data collection filters that use 3D information ? (pose, 3d rotation, etc). As explained before, using single shot models to estimate these values with highly distorted cameras will end up with trashy values

Yup, use recent best model brings me some issues and we would need to redesign some part of the code to assign camera model configuration to board detections. Your temporary workaround is addressed in 494fcb4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants