Python

C++ runs the real-time core of most SLAM systems, but Python is the language of everything around that core. In a typical SLAM workflow you will use Python for three things:

Many core SLAM libraries expose Python bindings, so you can prototype full pipelines without touching C++:

LibraryPython entry point
OpenCVopencv-python (cv2)
GTSAMofficial Python wrapper
g2ocommunity bindings (e.g. g2opy)
Open3Dnative Python API (point clouds, ICP, TSDF)

A common and productive pattern is prototype in Python, port to C++: validate the algorithm with cv2 + NumPy on a dataset, then reimplement the hot loop in C++/Eigen once the design is stable. For research code that must stay in Python, pybind11 lets you wrap the performance-critical C++ pieces and keep the experiment logic in Python — the best of both worlds.

Practical habits worth adopting early: use virtual environments (venv/conda/uv) per project, pin dependency versions for reproducibility, and remember that NumPy uses row-major conventions and OpenCV images are indexed [row, col] = [y, x] — a classic source of transposed-coordinate bugs.

A taste of SLAM tooling in Python

The single most useful script to have in your toolbox is trajectory evaluation. Aligning an estimate to ground truth with the closed-form least-squares rigid alignment (Umeyama’s method, via SVD) and computing ATE RMSE is a dozen lines of NumPy:

import numpy as np

def align_and_ate(P_est, P_gt):          # both Nx3
    mu_e, mu_g = P_est.mean(0), P_gt.mean(0)
    U, S, Vt = np.linalg.svd((P_gt - mu_g).T @ (P_est - mu_e))
    D = np.diag([1, 1, np.sign(np.linalg.det(U @ Vt))])
    R = U @ D @ Vt                        # rotation aligning est -> gt
    t = mu_g - R @ mu_e
    err = P_gt - (P_est @ R.T + t)        # residuals after alignment
    return np.sqrt((err ** 2).sum(1).mean())   # ATE RMSE

This is essentially what the widely used evo package (pip install evo) does — in practice, use evo for TUM/KITTI/EuRoC formats, plots, and RPE, but knowing the math above keeps its output from being a black box.

Making Python fast enough

Python’s slowness is almost entirely a loops problem. The rules of thumb:

Common pitfalls

Why it matters for SLAM

Modern SLAM research lives at the intersection of geometry and learning, and the learning half speaks Python. Even for classical systems, the evaluation, visualisation, and dataset tooling ecosystem is Python-based; being fluent in it makes you dramatically faster at running experiments and understanding what your C++ system is actually doing.

Hands-on