feat(kornia-slam-py): PyO3 high-level ORB-SLAM bindings#34
Draft
edgarriba wants to merge 1 commit into
Draft
Conversation
Adds `crates/kornia-slam-py`, a maturin-built Python extension exposing the SLAM driver as a single class. The user constructs one `OrbSlam` instance, feeds frames via `slam.process(image)` (numpy gray or RGB uint8), and queries the live map across calls via `slam.map_points()`, `slam.current_pose`, `slam.num_active_map_points`, and `slam.current_keyframe_idx`. The GIL is released inside `process()` so the SLAM work runs without blocking other Python threads. Surface: `OrbSlam`, `PinholeCamera`, `TrackingResult`, `TrackingStatus`, re-exported from `kornia_slam` (native module at `kornia_slam._kornia_slam`). Pipeline orchestration is duplicated from `examples/orb_slam/src/` — the example crate is intentionally untouched. `PIPELINE_SYNC.md` in the new crate documents the source-of-truth files and the fork commit. Three small workspace-level fixes were needed for the build to succeed: - `crates/kornia-sensors`: `feat/slam-utils` branch was deleted upstream, repointed to `main`. - `crates/kornia-slam/src/map.rs`: two `BaObservation` literals were missing `depth_meas` / `depth_sigma` after the upstream kornia-3d added those fields. Set both to inert defaults (`None`, `0.0`) — they are monocular, no metric depth. - Workspace `Cargo.toml`: `exclude = ["crates/kornia-slam-py"]` so the binding crate has its own lockfile and `pyo3/extension-module` feature unification doesn't leak. Design spec: `docs/superpowers/specs/2026-05-22-pyo3-orb-slam-bindings-design.md` (gitignored; available locally). Verified: `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `maturin build`, `pytest tests/python/` (15 passing). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Member
Author
|
@cjpurackal would love your high-level feedback on the shape of this — the Python API surface (one |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
crates/kornia-slam-py: maturin-built Python extension that exposes the SLAM driver as a single class. Construct oneOrbSlam, feed frames viaslam.process(image)(numpy gray or RGB uint8), query the live map across calls.process()(viaPython::allow_threads), so multi-threaded Python callers aren't blocked while SLAM crunches.examples/orb_slam/src/— the example crate is intentionally untouched.PIPELINE_SYNC.mddocuments the fork.Python surface
Workspace-level fixes (necessary to build)
crates/kornia-sensors/Cargo.toml:feat/slam-utilsbranch was deleted upstream → repointed tomain.crates/kornia-slam/src/map.rs: twoBaObservationliterals were missing the newdepth_meas/depth_sigmafields that upstreamkornia-3dadded. Set both to inert defaults (None,0.0) — monocular, no metric depth.Cargo.toml:exclude = ["crates/kornia-slam-py"]so the binding crate has its own lockfile andpyo3/extension-modulefeature unification can't leak into other workspace members.Design
Design spec at
docs/superpowers/specs/2026-05-22-pyo3-orb-slam-bindings-design.md(gitignored under the repo'sdocs/rule; available locally). Key decisions captured there:crates/kornia-slam-py(H,W) u8gray or(H,W,3) u8RGBPinholeCameraPython classslam.process(image)process()returnTrackingResult { pose, status, frame_idx }slam.map_points()→(N, 3) f64process()maturinTest plan
cargo fmt -- --check(new crate)cargo clippy --all-targets -- -D warnings(new crate)cargo check -p kornia-slam -p orb_slam(existing workspace still builds)maturin buildproduces a wheelpytest tests/python/— 15 tests passing (construction, gray/RGB input, frame-idx monotonic, map_points shape/dtype, error handling for wrong dtype / rank / channels, PinholeCamera distortion validation, TrackingStatus equality + repr)OrbSlam, feed 8 frames, querymap_pointsandcurrent_poseacross calls — runs cleanlyslam.process()and confirm map points / pose match what the Rust example producesOut of scope (v1, explicit non-goals)
.pyitype stubsOpen implementation questions
#[pymethods]macro expansion emits.into()onPyResult<T> -> PyResult<T>on stable rustc 1.93+, which clippy flags asuseless_conversion. Suppressed crate-wide via#![allow(clippy::useless_conversion)]inlib.rsuntil pyo3 upstream fixes it.edition = "2021"(vs the rest of the workspace's2024) because pyo3 0.22 generates code that trips Rust 2024's defaultunsafe_op_in_unsafe_fnlint.Related upstream tickets
While writing this binding I had to hand-roll a couple of pieces that really belong upstream in
kornia-rs. Filed for follow-up so future Python-facing crates don't redo the same work:kornia-algebrato PyO3 (matrices/vectors/Lie groups). Would replace the ad-hocPose3d -> ndarray(4,4)andintrinsic_matrix -> ndarray(3,3)marshalling in this crate.VideoReaderto PyO3 with time + keyframe seek. Would letOrbSlambe driven directly from an.mp4instead of pre-decoded numpy frames.🤖 Generated with Claude Code