Search

Search papers and lessons

Bundle Adjustment

Level 4 · 16 min read

Bundle adjustment refines camera poses and 3D point positions together so that the predicted image points match the measured ones as closely as possible.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Probability
  • Classical models
  • Losses & regularization
  • Computer vision
  • Sign in to see your progress

TL;DR

Bundle adjustment is the joint refinement of camera poses and 3D point positions. You start from rough estimates, project every 3D point into every camera that saw it, and adjust all the unknowns to shrink the gap between those projections and the pixels actually measured. The result is the most likely scene and camera motion under the assumption that pixel noise is independent and Gaussian.

It is the final accuracy step in most structure-from-motion and visual SLAM systems, and it is what turns a loose reconstruction into a consistent map.

Where you'll see it: in the mapping thread of ORB-SLAM, in 3D reconstruction from photo collections, and in drone and phone systems that track their own pose from a camera.

Intuition

Why the cameras and the points must move together

Suppose you have two photos of a building and you have matched a corner in both. From the two pixel positions you can triangulate where the corner is in 3D, but only if you already know where the cameras were. Your camera poses came from an earlier estimate, and that estimate has errors. Those errors make the triangulated point wrong, and the wrong point then makes the camera poses look wrong too.

Each estimate is tangled with the others. Bundle adjustment solves for all of them at once, so that every point sits where the cameras agree it should be. The name comes from photogrammetry, where each camera contributes a bundle of light rays through its optical centre, and the whole bundle is adjusted together.

The picture in one dimension

Take a single point at depth ZZ and a camera with focal length 1. Its image coordinate is u=X/Zu = X / Z, so a point that is twice as far away appears half as far from the image centre. Moving the camera sideways shifts every point's image by an amount that depends on its depth. This parallax is what lets the images pin down depth at all.

11.522.533.544.5500.20.40.60.811.2depth Zimage coordinate u
  • u = 1 / Z
  • u = 1.5 / Z
A point at depth 2 with X = 1 projects to u = 0.5. The same image coordinate would come from a point at X = 1.5 and depth 3, so one view alone cannot fix both. More views break the tie.

The math

Unknowns

There are mm cameras and pp points. Camera jj has a rotation RjR_j (a Rotation Matrix, three numbers in practice) and a translation tj\mathbf{t}_j (three numbers), so six parameters per camera. Point ii has a position Xi\mathbf{X}_i in 3D, three numbers. Collect them as

θ=({Rj,tj}j=1m,{Xi}i=1p).\boldsymbol{\theta} = \left(\{R_j, \mathbf{t}_j\}_{j=1}^{m}, \{\mathbf{X}_i\}_{i=1}^{p}\right).

Projection

Camera jj sees point ii when it is in front of the camera. Its position in camera coordinates is xijcam=RjXi+tj\mathbf{x}_{ij}^{\text{cam}} = R_j \mathbf{X}_i + \mathbf{t}_j. The Pinhole Camera Model then gives the predicted pixel, with intrinsic matrix KK containing focal length and principal point:

π(Xi;Rj,tj)=dehom⁡ ⁣(K(xcam/zcamycam/zcam1)),\pi(\mathbf{X}_i; R_j, \mathbf{t}_j) = \operatorname{dehom}\!\left( K \begin{pmatrix} x^{\text{cam}}/z^{\text{cam}} \\ y^{\text{cam}}/z^{\text{cam}} \\ 1 \end{pmatrix} \right),

where dehom⁡\operatorname{dehom} takes the first two entries of a homogeneous vector after dividing by the third. In words: the point is rotated and shifted into the camera frame, divided by its depth, and then scaled and shifted by the intrinsic matrix.

The objective

Let uij\mathbf{u}_{ij} be the measured pixel of point ii in image jj, and let vijv_{ij} be 1 if point ii is visible in image jj and 0 otherwise. Bundle adjustment minimises the sum of squared reprojection errors:

E(θ)=∑i=1p∑j=1mvij∥uij−π(Xi;Rj,tj)∥2.E(\boldsymbol{\theta}) = \sum_{i=1}^{p} \sum_{j=1}^{m} v_{ij} \left\| \mathbf{u}_{ij} - \pi(\mathbf{X}_i; R_j, \mathbf{t}_j) \right\|^2.

If pixel noise is independent and Gaussian with equal variance, minimising EE is maximum likelihood, which is the reason the squared error appears (see Maximum Likelihood Estimation). Weighting each term by the inverse pixel covariance gives the correct likelihood when noise differs across features.

Solving it: Gauss–Newton and Levenberg–Marquardt

Stack all the residuals r(θ)\mathbf{r}(\boldsymbol{\theta}), the differences between measured and predicted pixels. Let JJ be the Jacobian of r\mathbf{r} with respect to θ\boldsymbol{\theta}, as in the Jacobian Matrix. Each Gauss–Newton step solves the normal equations

J⊤J Δθ=−J⊤r,J^{\top} J \, \Delta\boldsymbol{\theta} = -J^{\top} \mathbf{r},

then updates θ←θ+Δθ\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} + \Delta\boldsymbol{\theta}. The Nonlinear Least Squares method is the general version of this loop. Levenberg–Marquardt adds damping, solving (J⊤J+λI)Δθ=−J⊤r(J^{\top} J + \lambda I) \Delta\boldsymbol{\theta} = -J^{\top} \mathbf{r}, and increases or decreases λ\lambda depending on whether the error went down.

The sparse structure and the Schur complement

Each residual depends on exactly one camera block and one point block. So the matrix J⊤JJ^{\top} J is sparse. Order the unknowns as camera parameters c\mathbf{c} and point parameters p\mathbf{p}. The normal equations have the block form

(UWW⊤V)(ΔcΔp)=(gcgp).\begin{pmatrix} U & W \\ W^{\top} & V \end{pmatrix} \begin{pmatrix} \Delta\mathbf{c} \\ \Delta\mathbf{p} \end{pmatrix} = \begin{pmatrix} \mathbf{g}_c \\ \mathbf{g}_p \end{pmatrix}.

Here VV is block diagonal with one 3×33 \times 3 block per point, because two points do not interact directly. That makes V−1V^{-1} cheap. Eliminating the points with the Schur Complement gives a smaller system only for the cameras:

(U−WV−1W⊤)Δc=gc−WV−1gp.\left(U - W V^{-1} W^{\top}\right) \Delta\mathbf{c} = \mathbf{g}_c - W V^{-1} \mathbf{g}_p.

After solving this, the point updates come back by substitution: Δp=V−1(gp−W⊤Δc)\Delta\mathbf{p} = V^{-1}(\mathbf{g}_p - W^{\top} \Delta\mathbf{c}). Almost all practical bundle adjustment codes use this trick.

Gauge freedom

The objective does not change if you rotate and translate the whole scene together with the cameras, so those directions are unobservable. With a single monocular camera the overall scale is also unobservable, because scaling the scene and the translations together leaves every pixel unchanged. That is 7 gauge degrees of freedom: 3 translation, 3 rotation and 1 scale. Practical systems fix them by holding one camera pose fixed, or by adding a prior. Without this, the normal equations are singular.

Worked examples

Example
One point, one camera, one Gauss–Newton step

Take a camera at the origin with rotation R=IR = I, translation t=0\mathbf{t} = 0, and focal length 1, so the pinhole projection is u=X/Zu = X / Z and v=Y/Zv = Y / Z. The point is at X=(1,2,4)\mathbf{X} = (1, 2, 4), with predicted pixel (0.25,0.5)(0.25, 0.5). The measured pixel is (0.30,0.50)(0.30, 0.50).

  1. Residual: r=u−π(X)=(0.30−0.25,  0.50−0.50)=(0.05,0)\mathbf{r} = \mathbf{u} - \pi(\mathbf{X}) = (0.30 - 0.25, \; 0.50 - 0.50) = (0.05, 0).
  2. Squared error: E=0.052+02=0.0025E = 0.05^2 + 0^2 = 0.0025.
  3. Jacobian of the residual with respect to the point's XX-coordinate, with ZZ fixed at 4: ∂ru∂X=−1Z=−0.25\dfrac{\partial r_u}{\partial X} = -\dfrac{1}{Z} = -0.25 and ∂rv∂X=0\dfrac{\partial r_v}{\partial X} = 0.
  4. The normal equation J⊤J ΔX=−J⊤rJ^{\top}J\,\Delta X = -J^{\top}\mathbf{r} reads 0.0625 ΔX=−(−0.25)(0.05)=0.01250.0625 \, \Delta X = -(-0.25)(0.05) = 0.0125, so ΔX=0.2\Delta X = 0.2.
  5. The new XX is 1.21.2, and the new prediction is 1.2/4=0.301.2 / 4 = 0.30, which matches the measurement exactly.

Interpretation: with one camera and fixed depth the problem is linear in XX, and one step is enough. Real problems couple the depth and the camera pose too, so several iterations are needed.

Example
Size of the problem for a realistic reconstruction

Consider 50 cameras and 10,000 points, with each camera visible to a fraction of the points.

  1. Camera unknowns: 50×6=30050 \times 6 = 300. Point unknowns: 10,000×3=30,00010{,}000 \times 3 = 30{,}000. Total: 30,30030{,}300.
  2. A dense normal matrix would have 30,3002≈9.2×10830{,}300^2 \approx 9.2 \times 10^8 entries, which is about 7 GB in double precision. Most of those entries are zero.
  3. After the Schur complement, the camera system is 300×300300 \times 300, which has 90,00090{,}000 entries and can be solved directly.
  4. Inverting VV is cheap because it is block diagonal with 10,00010{,}000 blocks of size 3×33 \times 3.

Interpretation: the sparse structure reduces the work from the size of the full system to a few small solves. This is why bundle adjustment on thousands of points is practical on ordinary hardware.

Example
Counting degrees of freedom before solving

Three cameras all see four points, and each observation gives two pixel residuals.

  1. Observations: 3×4×2=243 \times 4 \times 2 = 24 residuals.
  2. Unknowns: 3×6+4×3=303 \times 6 + 4 \times 3 = 30.
  3. Gauge freedom for a monocular setup removes 7 unknowns, leaving 30−7=2330 - 7 = 23 independent unknowns.
  4. Since 24≥2324 \geq 23, the problem is just overdetermined. Solving is possible but barely, and noise in any one pixel will be strongly visible.

Interpretation: a count like this is a quick check that a reconstruction is well posed. With only two views, the same calculation shows the problem is underdetermined unless the points are seen in more views.

Tradeoffs and failure modes

Bundle adjustment is the most accurate joint estimate of structure and motion from images, but it is costly and sensitive to bad starting points.

SituationWhat goes wrongBetter choice
Starting from a poor initial poseGauss–Newton converges to a wrong local minimumUse a good initialiser, such as essential-matrix estimation or incremental registration
Many wrong feature matchesOutliers dominate the squared errorUse a robust loss such as Huber or Cauchy, or remove outliers with RANSAC first
Very large scenes with millions of pointsEven the Schur-reduced system is too slowUse local windowed bundle adjustment or pose graph optimisation
Real-time tracking with a tight budgetFull bundle adjustment every frame is too expensiveOptimise a sliding window of recent frames, as in visual-inertial systems
Forgetting gauge fixingThe normal equations are singular and the solver divergesFix one pose and the scale, or add a weak prior

The main alternative for online tracking is Visual SLAM with a pose graph, which optimises only the relative constraints between keyframes and is much cheaper.

History

Bundle adjustment grew out of photogrammetry in the middle of the twentieth century, where engineers needed precise maps from aerial photographs. Duane Brown's work in the late 1950s and 1960s on the analytical calibration of cameras and bundles of rays set up the modern formulation.

Computer vision adopted it in the 1990s. A 2000 survey by Bill Triggs and co-authors, titled "Bundle Adjustment: A Modern Synthesis," explained the method for vision researchers and described the sparse structure that makes it practical. The Schur complement elimination became the standard trick in that period.

It caught on because it is the most reliable way to finish a reconstruction. Photo-collection systems such as the 2006 "Photo Tourism" work used it to reconstruct cities from internet photos, and open-source tools based on sparse solvers made it available to robotics groups. Today almost every structure-from-motion and visual SLAM pipeline ends with a bundle adjustment step, and many run a local version continuously.

Check yourself

QuestionRecall: why does bundle adjustment solve for camera poses and point positions together instead of one after the other?Show answer

Each estimate depends on the other. A point's 3D position is computed from camera poses, and the camera poses are checked against the points they project to. If you fix the cameras and triangulate the points, any error in the cameras goes straight into the points and is never corrected. Solving jointly lets the errors in both shrink together, so the final estimate is consistent with every measured pixel.

QuestionFor a single point at X=(2,0,5)\mathbf{X} = (2, 0, 5) seen by a camera at the origin with focal length 1, what are the predicted pixels? The measurement is (0.5,0.1)(0.5, 0.1). What is the squared reprojection error?Show answer

The predicted pixel is (2/5,0/5)=(0.4,0)(2/5, 0/5) = (0.4, 0). The residual is (0.5−0.4,  0.1−0)=(0.1,0.1)(0.5 - 0.4, \; 0.1 - 0) = (0.1, 0.1). The squared error is 0.12+0.12=0.020.1^2 + 0.1^2 = 0.02.

QuestionWhy is the point block VV in the normal equations easy to invert, and why does that matter?Show answer

Two points do not appear together in any residual, so VV has no off-diagonal blocks between different points. It is block diagonal with one small 3×33 \times 3 block per point, and each block is inverted independently at low cost. Eliminating the points with the Schur complement then leaves a system only over the cameras, whose size grows with the number of cameras rather than the number of points. For large scenes with many points, this is the difference between a practical solver and an impractical one.

QuestionA monocular reconstruction has 4 cameras and 9 points, and each point is seen by all 4 cameras. How many residuals and how many independent unknowns are there, after removing gauge freedom? Is the problem overdetermined?Show answer

Residuals: 4×9×2=724 \times 9 \times 2 = 72. Unknowns: 4×6+9×3=24+27=514 \times 6 + 9 \times 3 = 24 + 27 = 51. Removing the 7 gauge degrees of freedom leaves 51−7=4451 - 7 = 44 independent unknowns. Since 72≥4472 \geq 44, the problem is overdetermined, with 28 more residuals than unknowns. That slack is what lets least squares average out pixel noise.

Sources