Skip to content

Add a matrix-weighted localization example with a stereo camera - #2960

Open
avinashresearch1 wants to merge 4 commits into
borglab:developfrom
avinashresearch1:avi/stereo-localization-example
Open

avinashresearch1 wants to merge 4 commits into
borglab:developfrom
avinashresearch1:avi/stereo-localization-example

Conversation

@avinashresearch1

@avinashresearch1 avinashresearch1 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

[WIP] still being reviewed by Avinash

Closes #2958.

This example shows how to use GTSAM’s stereo camera model to generate anisotropic measurement weights for matrix-weighted localization. It builds a downward-facing stereo camera trajectory, perturbs the pixel observations, and propagates that noise through backprojection to obtain a covariance for each landmark observation. The notebook writes the resulting graph to g2o, reads it back, and compares a local solve with the chordal SDP certificate when MOSEK is available.

The example changes are the last three commits on the branch:

  • Expose write_g2o as a module-level function so an example can supply its own poses, landmarks, measurement information, and odometry noise. The dataset method still delegates with its existing defaults.
  • Let the C++ certifiable localization example take an optional g2o path.
  • Add the stereo localization notebook, including plots and an optional MOSEK certificate.

The first commit is the stereo covariance API from #2959, which the notebook calls. The fork PR isolates the three example commits for review.

The fork PR records full Python test discovery, notebook runs with and without MOSEK, C++ example runs on both the bundled and stereo datasets, and the code-quality checks. It also documents the existing GCC warning encountered in the MOSEK build.


🤖 Posted by an AI agent · harness: unknown · model: unknown
Review: unreviewed
Session: 01a1d519-ba1b-7961-bb2c-d47306ad294e

avinashresearch1 and others added 4 commits November 29, 2026 06:35
Add StereoCamera::backprojectWithCovariance, which back-projects a stereo
measurement and returns the point with its first-order covariance
H * Sigma_z * H^T, where H is the Jacobian of backproject2 with respect to
the measurement, evaluated at the measurement. One overload takes the 3x3
covariance of (uL, uR, v) and the other an isotropic pixel sigma. The point
and its covariance are both in the world frame.

Wrap both overloads for Python, test them in C++ and Python against the
closed form of Holmes, Dümbgen and Barfoot (T-RO 2024, App. E), and
document the method in StereoCamera.ipynb. Correct the backproject2 doc
comment and notebook section, which described H2 as the derivative with
respect to the point rather than the measurement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LandmarkLocalizationDataset.write_g2o writes the class's own poses and
landmarks, with the odometry noise fixed at ODOMETRY_SIGMA = 0.1, so other
landmark localization problems cannot use it. Move its body to a module-level
write_g2o(filename, wTks, wLs, measurements, odometry_sigma), and have the
method call it with the class's values. The committed
known_landmark_localization_3.g2o and _20.g2o files are unchanged, which the
existing reproducibility test checks.

Test that the new function writes the poses, landmarks and odometry sigma it
is given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CertifiableLocalizationExample takes an optional path to a g2o file. Without
one it solves known_landmark_localization_20.g2o, as before. The stereo
localization notebook writes a file in the same format, and the example
solves that file too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add CertifiableStereoLocalization.ipynb, "Matrix-weighted localization with a
stereo camera". A downward-looking stereo camera on a ring of 20 poses
observes 8 known landmarks, as in the matrix-weighted example of Duembgen,
Holmes and Barfoot (WAFR 2024) with its random poses replaced by a ring.
StereoCamera.backprojectWithCovariance turns noisy pixels into points with
full covariances, needles 40 to 67 times longer than they are wide. The
notebook writes the problem with LandmarkLocalizationDataset.write_g2o, reads
it back as a certifiable graph, solves it with Levenberg-Marquardt, certifies
the solution with the chordal SDP, and plots the covariance ellipsoids and
trajectories with Plotly. The SDP cell is skipped without MOSEK, as in the
certifiable localization example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

Reviewed 9fdfe3da6c47dcb40bc96c14103c1c252ce99bae → 5b484765dec82d8005795fe1b87b5850a3a523fd.

[P2] Check solver convergence before claiming global certification.
CertifiableStereoLocalization.ipynb, lines 433–447

The boolean returned by sdp.solve() does not establish optimality: SolveMosekModel marks the solve completed after MOSEK returns, including an early termination. Moreover, objectiveValue() reads MOSEK's primal objective with AccSolutionStatus::Anything. If MOSEK stops at the configured 600-second limit or a numerical stop, that value is not established as a lower bound. Comparing it with the local cost and checking rank-one blocks does not repair this: a feasible rank-one lift of a suboptimal local solution can satisfy both checks without a global certificate.

Require a solver solution status establishing optimality before treating the primal optimum as an approximate lower bound, or compare against a valid dual bound with the appropriate feasibility/convergence checks. Otherwise report the outcome as uncertified. The current fixed example converges successfully; its small negative gap is ordinary numerical tolerance, not evidence of false certification.

Validation:

  • Relevant Python tests passed: 5 tests, including both covariance overloads and the dataset writer.
  • Existing C++ testStereoCamera binary passed; the relevant source files match this PR.
  • Executed the notebook's code cells in existing stereo-capable environments both without MOSEK and with MOSEK, suppressing interactive display. Both paths passed; MOSEK diagnostics report Optimal, objective ≈268.603 and minimum EVR ≈1.2e12.
  • Ran the existing C++ example against the notebook-generated g2o file; both SDP formulations recovered matching costs.
  • git diff --check passed.

Limitations: reused existing builds rather than rebuilding GTSAM; MATLAB calls and the Colab installation path were not exercised. No code changes made.

Review by Codex.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Example: matrix-weighted localization using GTSAM's stereo camera model

1 participant