Implemented UP2p minimal solver#834
Conversation
|
One Question @cjpurackal should i push the script code too which i wrote to test the functionality on the images . |
|
How did you test/verify this? |
|
I wrote a script to run test it on the image i provided in the description i can push that code if you allow . |
|
what's you understanding of this solver and how does it translate to the test you wrote? |
|
@cjpurackal
|
okay, now can you give me some plots comparing epnp and up2p for this dataset confirming the claim? |
The tests I wrote did not generate plots ,they output a comparison table showing inlier counts, reprojection RMSE, translation, and rotation angle for both EPnP and UP2P on the same EuRoC MH_01_easy dataset. I will write a plotting script to visualize the results and will share those plots here shortly. This is the table :EPnP vs UP2P — Real Image Comparison (EuRoC MH_01_easy)[✓] Loaded EuRoC MH_01_easy frames
[✓] Both solvers ran successfully on real EuRoC data! |
@cjpurackal Here is the plot for the same test.
|
|
@cjpurackal please take a look once you have some time. |
|
Updated @cjpurackal |
There was a problem hiding this comment.
Pull request overview
This PR adds a gravity-aware Upright 2-Point Perspective (UP2P) minimal PnP solver to kornia-3d and integrates it into the existing solve_pnp_ransac pipeline so RANSAC can use 2-point sampling and evaluate multiple pose hypotheses.
Changes:
- Added a new UP2P solver implementation (including unit tests) and exposed it via the
pnpmodule. - Extended
PnPMethodwith aUP2P(gravity)variant and introduced a multi-hypothesis dispatch (solve_pnp_multi) for RANSAC. - Updated
solve_pnp_ransacto (a) use dynamic minimal sample sizes (2 for UP2P, 4/5 for EPnP) and (b) evaluate multiple candidates per iteration.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
crates/kornia-3d/src/pnp/up2p.rs |
Implements UP2P minimal solver + conversion glue into PnPResult, with unit tests. |
crates/kornia-3d/src/pnp/ransac.rs |
Updates RANSAC to use solve_pnp_multi, handle UP2P’s 2-point sampling, and refine UP2P via EPnP fallback. |
crates/kornia-3d/src/pnp/mod.rs |
Registers UP2P module, adds PnPMethod::UP2P, and adds multi-hypothesis solver routing. |
| .unwrap_or_else(|_| best_pose.clone()) | ||
| } else { | ||
| best_pose |
There was a problem hiding this comment.
propogate the error better here i think this silently discards some errors
|
@sidd-27 Addressed the comment, |
| #[test] | ||
| fn test_ransac_up2p() -> Result<(), PnPRansacError> { | ||
| // Identity rotation and some translation |
There was a problem hiding this comment.
maybe add more comphrensive tests for ransac? this one covers the easiest case
There was a problem hiding this comment.
@sidd-27 Added few more complex test case , i have used ai to generate them but verified that they are correct .
|
Hi @cjpurackal is there anything else needs to be done for this pr ? |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
|
@cjpurackal v=can you take a look |

📝 Description
This PR adds the Upright 2-Point Perspective (UP2P) minimal solver to kornia-3d, allowing camera pose estimation from just 2 points when gravity is known from an IMU. It strictly integrates into the existing
solve_pnp_ransacpipeline, significantly reducing required RANSAC iterations while proving far more robust to noise than unconstrained solvers like EPnP.#826
Fixes/Relates to: # 826
Important:
🛠️ Changes Made
crates/kornia-3d/src/pnp/up2p.rsbased on the mathematical formulation from the PoseLib C++ reference.UP2Pdirectly into the existingsolve_pnp_ransacpipeline incrates/kornia-3d/src/pnp/ransac.rs, including adding asolve_pnp_multimatching function to evaluate multiple polynomial root hypotheses.🧪 How Was This Tested?
Used these images :
🕵️ AI Usage Disclosure
Check one of the following:
🚦 Checklist
💭 Additional Context
By using gravity data from a device's IMU, the UP2P solver already knows which way is "down." This means it doesn't have to guess the camera's tilt (roll and pitch).
Because it only has to figure out which direction the camera is facing (yaw) and its location, it only needs 2 points to solve the camera pose instead of the 5 needed by normal solvers like EPnP. This makes it much faster to compute, and much more accurate when dealing with messy, real-world data where normal solvers would just get confused by the noise.