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 camera matrix correction method #1650

Closed

Conversation

tuxbotix
Copy link
Contributor

@tuxbotix tuxbotix commented Feb 25, 2025

Why? What?

The current implementation of to_corrected() applies the new correction on top of existing corrected values. Since this method is used in camera calibration, the parameters obtained by the solver also reflects this issue.

Current state:

  • T = C_o * T_m at construction (C_o from parameter file)
  • T_n = C_n * T when using to_corrected()
  • So the total correction C_t will be C_o + C_n
  • Neither C_o, nor T_m are stored in CameraMatrix, so I'll have to read from parameter files and re-calculate this which is wonky IMO.

What we need:

  • T = C_o * T_m at construction (C_o from parameter file)
  • T_n = C_n * T_m when using to_corrected()

Changes:

  • This PR fixes it by storing the transformation values as per the theoritical model T_m so that corrections can always be done from that state. It is also verified by the added unit test.
  • Also introduces robot rotation values as extra corrections.

Fixes #

ToDo / Known Issues

  • Discuss and evaluate if we can do this differently

Ideas for Next Iterations (Not This PR)

If there are some improvements that could be done in a next iteration, describe them here.

How to Test

Describe how to test your changes. (For the reviewer)

@tuxbotix tuxbotix requested a review from oleflb February 25, 2025 18:56
@oleflb oleflb self-assigned this Feb 26, 2025
Copy link
Contributor

@oleflb oleflb left a comment

Choose a reason for hiding this comment

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

I did not fully get your explanation. Why do you have to apply the correction differently now? Reading the test case it seems like you want the correction to be idempotent, is this what you are after?

correction_robot,
);

let corrected_varient = camera_matrix.to_corrected(correction_robot, correction_camera);
Copy link
Contributor

Choose a reason for hiding this comment

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

corrected_variant

@tuxbotix
Copy link
Contributor Author

tuxbotix commented Feb 27, 2025

I did not fully get your explanation. Why do you have to apply the correction differently now? Reading the test case it seems like you want the correction to be idempotent, is this what you are after?

I'm sorry for my bad explanation, the reasoning starts from how it is constructed by camera matrix calculator Vs how get_corrected is used.

The parameters give the full amount of correction needed and camera matrix calculator applies it to the bead to camera matrix before building CameraMatrix. But there is no information about the correction nor the state before correction.

In the current state, get_corrected means whatever additional offsets needed, not the absolute correction. So the calibration solver using this function also returns the relative values.
That means I have to re-read the existing parameters and calculate the full amount of correction before writing to the parameters file.

What I want instead is to store the head to camera matrix before correction or less preferably the original correction value we added.
It is simply encapsulation of all the information instead of sourcing it from different places and build back.

@oleflb
Copy link
Contributor

oleflb commented Mar 2, 2025

Hmm I feel like the CameraMatrix struct shouldn't contain all of this state. Ideally it'd would only consist of Extrinsinc and Intrinsic. This is because the calibrations are only applied once in the extrinsic chain and then all nodes using the CameraMatrix work with the calibrated matrix (and they would never want to use the uncalibrated one). If you want the uncalibrated CameraMatrix, I would favor just creating a second instance of the existing CameraMatrix struct (uncalibrated_camera_matrix)

@tuxbotix
Copy link
Contributor Author

tuxbotix commented Mar 4, 2025

I just saw your reply, I was already thinking of how else we can do this and came to the same conclusion - have an uncalibrated camera matrix instance - since the camera matrix already contains a lot of information and I feel it is already overcomplicated.

As you said, in an ideal world we only need the two main matrices but our needs and design choices made it harder. Perhaps we can reconsider this design and see what can we do about it (i.e. we have many 180° rotations with recent axis changes).

I'll change the module and you can review again :)

@oleflb
Copy link
Contributor

oleflb commented Mar 10, 2025

I also ran into this issue and fully understand your pain now :D I still think having an uncalibrated and a calibrated variant is the best solution to this problem. Did you implement something like this already?

@tuxbotix
Copy link
Contributor Author

tuxbotix commented Mar 10, 2025 via email

@oleflb
Copy link
Contributor

oleflb commented Mar 13, 2025

This is implemented now in #1690. Please close if that PR suits your use case as well

@tuxbotix
Copy link
Contributor Author

Oh neat, that's the alternative I wanted to implement. So all good 😋

@tuxbotix tuxbotix closed this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants