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

Pinhole model support in C API for mrcal_rectified_system #30

Open
akonneker opened this issue Oct 11, 2024 · 8 comments
Open

Pinhole model support in C API for mrcal_rectified_system #30

akonneker opened this issue Oct 11, 2024 · 8 comments

Comments

@akonneker
Copy link

See here

I just stumbled over this while embedding mrcal rectification map calculation into some C++ code. I had previously used rectified_system with a pinhole model in the python api.

Do you have a timeline for when you might add this support?
Or perhaps you have some advice about an easier workaround than just using the python API?

@dkogan
Copy link
Owner

dkogan commented Oct 11, 2024

Hello. This is very low priority for me since pinhole rectification is strictly worse than latlon rectification in every way: https://mrcal.secretsauce.net/stereo.html

If you need this, you should implement it! It wouldn't be that difficult, and I would appreciate the contribution. Port the relevant logic in mrcal._rectified_system_python() to the C mrcal_rectified_system() function. There already exists a test that makes sure that the not-yet-written port is correct: test-rectification-maps.py.

Thanks!

@akonneker
Copy link
Author

I'm happy to add the functionality, but can you help me understand how that test works to call the c function?
As-is it happily passes, when I would expect it to fail if it actually called the c version of the function.

@akonneker
Copy link
Author

Ah, I suppose I need to undo this behavior in stereo.py:

NOTE: THE C IMPLEMENTATION HANDLES LENSMODEL_LATLON only. The

@dkogan
Copy link
Owner

dkogan commented Oct 14, 2024

Yep. The python function mrcal.rectified_system() is the outer logic, and it makes sure to call the Python code when using pinhole models:

if rectification_model == 'LENSMODEL_PINHOLE':

So you're remove that if statement entirely. Right after that, it calls mrcal._mrcal._rectified_system(), which routes to the C code.

@akonneker
Copy link
Author

akonneker commented Oct 14, 2024

So I have it implemented, and test-stereo.py and test-rectification-maps.py are now passing.

The primary issue is how to replace the root-finding provided by numpy with something in c. I found this as a possible solution: https://github.com/yairchu/quartic. It's BSD licensed and only two files (for the c implementation), so it seems to me to be a reasonable solution to include the files directly in mrcal, but that's up to you to decide.

I found another issue when working on this: there are missing docstring files that are referenced in mrcal-pywrap.c that don't exist in the repo:
measurement_index_points_triangulated
num_measurements_points_triangulated
decode_observation_indices_points_triangulated

I just commented those out to move forward, but I thought you should know.

@dkogan
Copy link
Owner

dkogan commented Oct 14, 2024 via email

@dkogan
Copy link
Owner

dkogan commented Oct 24, 2024

Hi. Are you still trying to do this? Do you need help?

@akonneker
Copy link
Author

Sorry for the delayed response. My quick hack satisfied my initial need and I've been pretty busy at work since then. I'll come back to this in another week or so when things slow down.

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

No branches or pull requests

2 participants