Foundations to Frontier
Tests

Structure from Motion and Visual SLAM

Structure from motion (SfM) recovers camera poses and a 3-D point cloud from overlapping photos. Visual SLAM does the same incrementally and in real time from a moving camera. Both rest on the same geometry. Matched features obey the epipolar constraint x₂ᵀ F x₁ = 0. The essential matrix E = [t]ₓR gives the relative rotation and the direction of translation. Triangulation turns matches into 3-D points, and bundle adjustment refines all poses and points by minimising reprojection error. This page covers the eight- and five-point algorithms, RANSAC, triangulation, scale ambiguity, bundle adjustment with sparse solvers, and how COLMAP, GLOMAP, ORB-SLAM3, DROID-SLAM and feed-forward models such as VGGT fit together. Robot-centred SLAM, with inertial sensors and pose graphs, is covered in the robotics sections. In the exercises you build the essential matrix, run the normalised eight-point algorithm and triangulate. You then estimate two-view pose from 200 noisy matches. Hartley normalisation cut the translation-direction error from 14.6° to 2.3°, and bundle adjustment cut it to 0.43°. With 30% outliers the error was 70° without RANSAC and 6.5° with it. A Huber loss on all matches, instead of RANSAC, gave 12.8°.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Rebuilding a scene from photos

Walk around a statue taking photos and a computer can rebuild it in 3-D. It finds the same small features in different photos, works out where each photo was taken from, and then intersects the lines of sight to place each feature in space. Two things make this work: the photos must be taken from different positions (turning on the spot gives no depth), and the wrong matches must be thrown out. A final polishing step, bundle adjustment, nudges all cameras and points together until every point lands where it was seen. The demo shows why a wider spacing between views pins down depth much better.

3-D vision lab
The rays meet at 0.69°. With ±1 px of ray error the point lies between 7.50 m and 15.00 m (shaded). Wider baselines give larger angles and shorter, better-defined regions.
Why engineers care

Drone photogrammetry, Mars terrain maps from rover and orbiter images, AR headsets and robot navigation all run structure from motion or visual SLAM.

📝 Quick check (Level 0)
0/3 answered
  1. 1. To recover depth, the camera must…
  2. 2. Lines of sight from two views are intersected by…
  3. 3. Bundle adjustment minimises…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Epipolar geometry: a point in image 1 must lie on a line in image 2. Pixel matches satisfy x₂ᵀ F x₁ = 0 with the fundamental matrix F (rank 2, 7 degrees of freedom); with known intrinsics, normalised coordinates satisfy y₂ᵀ E y₁ = 0 with E = [t]ₓR = Kᵀ F K (5 degrees of freedom, singular values σ, σ, 0).
  • Estimation: eight-point algorithm (Longuet-Higgins, 1981) with Hartley normalisation (1997); seven-point for F; five-point for E (Nistér, 2004), which also works for planar scenes. Robust estimation with RANSAC (Fischler and Bolles, 1981), LO-RANSAC, PROSAC, MAGSAC++ (2020); Sampson error as the residual.
  • Pose from E: four (R, t) candidates; the one that puts triangulated points in front of both cameras wins (cheirality). Translation is recovered only up to scale; monocular systems need another cue (known object size, IMU, GPS) for metres.
  • Triangulation: linear DLT or the midpoint method; accuracy depends on the parallax angle between rays. Pure rotation or a tiny baseline gives no depth.
  • Bundle adjustment (BA): minimise Σ ‖π(Kᵢ, Rᵢ, tᵢ, Xⱼ) − xᵢⱼ‖² over all cameras and points with Levenberg–Marquardt; the Schur complement eliminates points so only a small camera system is solved (Triggs et al., 2000). Robust losses (Huber, Cauchy) limit residual outliers. Solvers: Ceres, g2o, GTSAM.
  • SfM pipelines: incremental (Bundler 2006, COLMAP 2016: register images one by one, triangulate, BA) or global (rotation averaging, then translations: GLOMAP 2024). Feed-forward 3-D models (DUSt3R and MASt3R 2024, VGGT 2025) predict point maps and cameras directly and increasingly initialise or replace parts of the pipeline.
  • Visual SLAM: tracking against a local map, keyframes, local BA, place recognition with bag of words (DBoW2) and loop closure with pose-graph optimisation to remove drift. Feature-based: PTAM (2007), ORB-SLAM3 (2021); direct: LSD-SLAM (2014), DSO (2018); learned: DROID-SLAM (2021), DPVO (2023), MASt3R-SLAM (2025).
📝 Quick check (Level 1)
0/3 answered
  1. 1. Degrees of freedom of the essential matrix:
  2. 2. Monocular SfM recovers translation…
  3. 3. Bundle adjustment eliminates points with…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Two-view geometry and refinement

Exercise 1.

  • The essential matrix E = [t]ₓR.
  • The normalised eight-point algorithm.
  • Linear triangulation and reprojection error.

Practice.

  • For a photo collection, run COLMAP (or GLOMAP for speed) with SIFT or a learned matcher (SuperPoint + LightGlue via hloc); inspect the number of registered images, track lengths and mean reprojection error.
  • Estimate E with the five-point algorithm inside RANSAC or MAGSAC (cv2.findEssentialMat, cv2.recoverPose), then refine with BA.
  • Fix scale with GNSS, a known distance or ground control points; georeference the reconstruction.
  • For real-time use choose ORB-SLAM3 (with IMU if available) or DROID-SLAM on a GPU; check drift on loops.
  • When views are few or textureless, try MASt3R or VGGT for initialisation and still bundle-adjust the result.
import cv2, numpy as np
K = np.array([[1200.0, 0, 960], [0, 1200, 540], [0, 0, 1]])
img1, img2 = (cv2.imread(f, cv2.IMREAD_GRAYSCALE) for f in ("frame_000.png", "frame_010.png"))
sift = cv2.SIFT_create(); k1, d1 = sift.detectAndCompute(img1, None); k2, d2 = sift.detectAndCompute(img2, None)
m = [a for a, b in cv2.BFMatcher().knnMatch(d1, d2, k=2) if a.distance < 0.8 * b.distance]
p1 = np.float32([k1[a.queryIdx].pt for a in m]); p2 = np.float32([k2[a.trainIdx].pt for a in m])
E, inl = cv2.findEssentialMat(p1, p2, K, method=cv2.USAC_MAGSAC, prob=0.999, threshold=1.0)
n, R, t, mask = cv2.recoverPose(E, p1, p2, K, mask=inl)          # cheirality check picks one of four poses
X = cv2.triangulatePoints(K @ np.eye(3, 4), K @ np.c_[R, t], p1[mask.ravel() > 0].T, p2[mask.ravel() > 0].T)
print(n, R, t.ravel(), (X[:3] / X[3]).T[:3])                    # t has unit length: the scale is unknown
🐍 Exercise 1: essential matrix, eight points, triangulation
Build E = [t]ₓR, estimate F with the normalised eight-point algorithm and triangulate a match with the DLT.
📝 Quick check (Level 2)
0/3 answered
  1. 1. OpenCV function that picks the valid pose from E:
  2. 2. A standard incremental SfM tool:
  3. 3. Metric scale for monocular SfM comes from…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

The epipolar constraint. If x₂ = R x₁ + t for the same point in the two camera frames, then t, x₂ and R x₁ are coplanar, so x₂ · (t × R x₁) = 0, which is y₂ᵀ [t]ₓ R y₁ = 0 in normalised coordinates. E = [t]ₓR has two equal singular values and one zero; enforcing this structure after the linear solve gives a valid essential matrix.

Why normalise. The eight-point system has entries like x₂x₁ (about 10⁵ for pixel coordinates) next to entries equal to 1. The smallest singular vector of such a badly scaled matrix is very sensitive to noise. Centring and scaling the points to mean distance √2 balances the columns (Hartley, 1997).

Scale and parallax. Multiplying t and all points by s leaves every image unchanged, so monocular reconstructions have one free scale. Depth precision depends on the parallax angle: for baseline B and depth Z the rays meet at about B / Z radians, and the depth error grows as Z² / B.

Bundle adjustment. With m cameras and n points the normal equations have size 6m + 3n, but each residual depends on one camera and one point. The Hessian is therefore sparse with 3 × 3 point blocks; eliminating them (Schur complement) leaves a 6m × 6m reduced camera system. This is why BA scales to millions of points. BA is maximum-likelihood under Gaussian pixel noise, but squared loss is badly affected by outliers, so outliers are removed by RANSAC first and robust losses limit what remains.

📝 Quick check (Level 3)
0/3 answered
  1. 1. E has singular values…
  2. 2. Monocular reconstructions are ambiguous up to…
  3. 3. BA scales to millions of points because…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

What do normalisation, RANSAC, bundle adjustment and baseline contribute to two-view pose and structure?

History.

  • H. C. Longuet-Higgins, “A computer algorithm for reconstructing a scene from two projections” (1981).
  • M. Fischler and R. Bolles, “Random sample consensus” (1981); R. Hartley, “In defense of the eight-point algorithm” (1997).
  • B. Triggs et al., “Bundle adjustment — a modern synthesis” (2000); D. Nistér, “An efficient solution to the five-point relative pose problem” (2004).
  • J. Schönberger and J.-M. Frahm, “Structure-from-motion revisited” (COLMAP, 2016); C. Campos et al., “ORB-SLAM3” (2021); J. Wang et al., “VGGT” (2025).

Exercise 2. 200 points in a 4 m × 4 m region 4–8 m ahead; f = 500 px, 640 × 480 images, 0.5 px noise. The second camera is rotated by a random rotation of typical size 5° and moved 0.5 m sideways. 12 trials; medians reported.

  • Methods: eight-point on raw pixels or with Hartley normalisation, followed by pose selection by cheirality. Then two-view bundle adjustment (Levenberg–Marquardt with a Schur complement). With 30% random outlier matches: plain eight-point, RANSAC (8-point samples, Sampson threshold 2 px, adaptive iterations, refits on inliers), RANSAC then BA, or RANSAC then a Huber-loss BA on all matches. Finally a 0.05 m baseline.
  • Measures: rotation error, angle between true and estimated translation direction, and median relative depth error of triangulated inlier points after fixing the scale with the true baseline length.
method rotation error (°) translation error (°) depth error
eight-point, raw pixels 2.223 14.56 0.262
eight-point, normalised 0.115 2.27 0.020
normalised + BA 0.1 0.43 0.018
30% outliers, no RANSAC 22.565 70.48 0.879
30% outliers, RANSAC 0.26 6.53 0.065
RANSAC + BA on inliers 0.4 2.97 0.066
RANSAC + Huber BA on all matches 1.223 12.76 0.190
baseline 0.05 m 0.128 13.27 0.224
baseline 0.05 m + BA 0.121 4.77 0.219
  • Normalisation matters: raw-pixel eight-point was 6–19 times worse in rotation on the three seeds (seeds 1 and 2: 1.346° against 0.144°, 0.703° against 0.117°).
  • Bundle adjustment mainly fixed the translation direction: 2.27° to 0.43° (seeds 1 and 2: 1.89° to 0.34°, 1.14° to 0.43°).
  • RANSAC is essential with outliers: without it the translation direction was essentially random (70°). RANSAC kept 3.2% of outliers and labelled 93% of matches correctly, but failed outright on 1 of 12 trials (4 of 12 on seed 2), which is why LO-RANSAC, MAGSAC and the five-point solver with fewer samples are used in practice.
  • Negative result: a Huber loss on all matches was worse than BA on RANSAC inliers on every seed (12.8° against 3.0°; seeds 1 and 2: 12.1° against 0.98°, 27.3° against 5.2°). Huber still gives gross outliers linear influence, so it does not replace outlier rejection. BA on inliers also made rotation worse on seeds 0 and 2 (0.26° to 0.4°, 0.441° to 0.896°), because accepted outliers and failed trials pull squared loss.
  • Baseline limits depth: with 0.05 m (about 0.5° of parallax) BA improved the translation direction to 4.8° but not the depth error (0.224 to 0.219; seed 2: 0.210 to 0.224). The information is simply not in the images.
  • Caveat: two views, synthetic points and outliers, known intrinsics; real SfM adds many views, track building and loop closure.
🐍 Exercise 2 (research): what do normalisation, RANSAC, bundle adjustment and baseline contribute to two-view pose and structure?
Estimate two-view relative pose from 200 noisy matches with the eight-point algorithm (raw and normalised), bundle adjustment, RANSAC under 30% outliers, a Huber loss, and a short baseline.

SfM and visual SLAM in AI, robotics and aerospace

  • Earth observation and mapping: drone photogrammetry (COLMAP, OpenDroneMap, Agisoft Metashape) bundle-adjusts thousands of images with ground control points to produce orthomosaics and surface models.
  • Planetary science: rover visual odometry on Mars, and SfM on orbiter and descent imagery for terrain models used in landing-site selection; OSIRIS-REx mapped asteroid Bennu with stereophotoclinometry and SfM-style methods.
  • Robotics and AR: ORB-SLAM3, VINS-Fusion and headset trackers run visual(-inertial) SLAM onboard; learned systems (DROID-SLAM, MASt3R-SLAM) are increasingly used where GPUs are available.

References

  1. R. Hartley and A. Zisserman (2004). Multiple View Geometry in Computer Vision, 2nd edition. Cambridge University Press.
  2. D. Nistér (2004). “An efficient solution to the five-point relative pose problem.” IEEE TPAMI.
  3. B. Triggs, P. McLauchlan, R. Hartley and A. Fitzgibbon (2000). “Bundle adjustment — a modern synthesis.” Vision Algorithms: Theory and Practice.
  4. J. L. Schönberger and J.-M. Frahm (2016). “Structure-from-motion revisited.” CVPR.
  5. L. Pan et al. (2024). “Global structure-from-motion revisited.” ECCV (GLOMAP).
  6. C. Campos et al. (2021). “ORB-SLAM3: an accurate open-source library for visual, visual-inertial and multimap SLAM.” IEEE T-RO.
  7. Z. Teed and J. Deng (2021). “DROID-SLAM: deep visual SLAM for monocular, stereo, and RGB-D cameras.” NeurIPS.
  8. J. Wang et al. (2025). “VGGT: visual geometry grounded transformer.” CVPR.