TL;DR
Structure from motion (SfM) takes a set of photos of one static scene and works out two things at once: the position and direction of the camera for each photo, and a sparse cloud of 3D points that the photos see. It finds points that appear in several images, triangulates them, adds one camera at a time, and then adjusts all cameras and points together to fit every observation.
It is the step that turns a folder of holiday photos or a phone video into the cameras and points that a 3D reconstruction or a renderer needs.
Where you'll see it: as the first stage of photogrammetry tools, as the camera-calibration step before training a neural renderer such as Gaussian Splatting, and in robotics as the core of visual mapping.
Intuition
Two unknowns, one set of pictures
Hold a coin at arm's length and look at it from the left, then from the right. The coin's edge looks different in the two views. Your brain uses that change to tell you the coin's shape and how far you moved your head. Structure from motion does the same thing with a computer.
The problem is circular. To locate a 3D point, you need to know where the cameras were. To know where the cameras were, you need to know where the 3D points are. SfM breaks the circle by starting small. It picks two photos, finds points they share, and works out their relative pose from those matches. Once the two cameras and some points are fixed, it can place a third camera by looking at points already in place, then add more points, and so on. At the end a single global refinement makes everything agree.
The key ingredient is that the photos overlap. Two photos of the same wall with a shared corner give one constraint. A hundred photos with dozens of shared features give the system enough constraints to pin down every camera and point.
flowchart LR A["Photos"] --> B["Detect features"] B --> C["Match features between pairs"] C --> D["Pick a starting pair"] D --> E["Triangulate points"] E --> F["Register next camera"] F --> G["Triangulate new points"] G --> H["Bundle adjustment"] H --> F H --> I["Cameras and sparse cloud"]
The math
Cameras
Each camera is a pinhole model (see Pinhole Camera Model). Its pose is a rotation and translation that take world points into its frame, so a world point lands at camera coordinates . The camera has intrinsics with focal length and principal point, and the image point is
Here divides by depth. Rotations are handled by rotation matrices or by a parameterisation such as a quaternion.
Two views and the epipolar constraint
For a point seen in views and at homogeneous pixel positions and , the epipolar constraint says the two rays and the baseline are coplanar. For normalised image coordinates this is , where is the essential matrix. Matching points that satisfy this constraint is how the starting pair is found. Real matches include wrong ones, so the estimate is run inside a robust loop that rejects outliers.
Triangulation
Once two cameras are known, a point is found by intersecting the two rays. With exact data the rays meet. With noise they do not, so the point is chosen to best fit both observations, usually by a linear least-squares solve on the stacked projection equations (see Singular Value Decomposition (SVD) for the solve).
Bundle adjustment
Every camera and point is refined together by minimising the reprojection error: the distance between each observed pixel and the pixel predicted by the current model. Writing for the set of observed pairs and for the measured pixel,
This is a nonlinear least-squares problem (see Nonlinear Least Squares). Its Jacobian is large but very sparse, because each residual depends on one camera and one point. Solvers exploit that sparsity, and damped Gauss-Newton steps (the Levenberg-Marquardt idea) keep each update stable. The Jacobian is the object from Jacobian Matrix.
Scale and gauge
Photos alone cannot give absolute scale. If every camera and point is scaled by the same factor, all images stay the same. Reconstructions are therefore known only up to a similarity transform: a rotation, a translation and one overall scale. Applications fix the scale from a known distance or from a GPS or ruler measurement.
Worked examples
Use a normalised camera with focal length 1, so and . Camera 1 sits at the origin. Camera 2 is translated one unit along , so its coordinates are .
- Place a 3D point at .
- In camera 1, .
- In camera 2, the point is at , so .
- The disparity is .
- For a rectified pair with baseline , depth is .
- Recover , which matches the original point.
Interpretation: the bigger the disparity, the closer the point. Wide baselines give larger disparities and more accurate depth, which is why SfM prefers photos taken from different positions.
Take the same setup but with a real focal length of pixels, and a point whose true image position in camera 2 is pixels.
- The feature detector reports the point at pixels in camera 2, which is an error of 40 pixels in one direction.
- The current model predicts pixels, so the residual is .
- The squared residual contributes to the bundle adjustment cost.
- If camera 2 is nudged slightly so that its predicted pixel moves to , the residual becomes zero. Bundle adjustment does this kind of nudge across all observations at once.
Interpretation: the cost is in pixels squared, not in metres. This is what lets SfM combine points from cameras at very different distances on one scale.
Suppose a capture has 50 cameras and 2000 points, and each point is seen by 5 cameras. Ignore intrinsics for now.
- Each camera has 6 pose parameters (3 for rotation, 3 for translation). The cameras need unknowns.
- Each point has 3 coordinates, so the points need unknowns.
- The total is unknowns.
- Each point seen by 5 cameras gives 5 observations, each with 2 pixel coordinates. That is equations.
- The system is over-determined by a wide margin, so the solution is well constrained once the gauge (scale and frame) is fixed.
Interpretation: the Jacobian has about rows and columns but only a few nonzeros per row. Sparse solvers are the reason bundle adjustment scales to thousands of photos.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Few shared features between photos | Starting pair is weak, and new cameras cannot be registered | Take photos with more overlap, or use more features |
| Repeated texture or symmetric structure | False matches that look correct locally | Geometric verification with a robust estimator |
| Pure rotation of the camera | Depth cannot be triangulated, because the baseline is zero | Use a capture with translation, or a rotation-only panorama method |
| Moving objects in the scene | Matches on people or cars break the static-scene assumption | Mask dynamic regions before matching |
| Long sequences | Drift accumulates when cameras are added one by one | Periodic global bundle adjustment, or loop closure |
| Need a dense surface | SfM gives only sparse points | Run multi-view stereo on the recovered cameras |
SfM is the right tool when the scene is static and the photos overlap. It is the wrong tool when the scene moves, when there is no texture, or when a dense surface is needed without a second stage.
History
Structure from motion grew out of photogrammetry, the older practice of measuring 3D shape from photographs with known cameras. The shift to unknown cameras came from computer vision work on projective geometry in the 1990s, which showed that a reconstruction is possible from images alone.
The modern incremental pipeline is usually traced to the Photo Tourism work of Snavely, Seitz and Szeliski in 2006, which reconstructed large collections of internet photos. The bundle adjustment step that refines everything jointly is much older, from photogrammetry, and it remains the core of the method.
Schönberger and Frahm's COLMAP pipeline, published at CVPR in 2016, made a robust incremental SfM system widely available. Gaussian splatting uses the output of such a pipeline as its starting cloud. The Kerbl et al. paper cites both Snavely et al. and Schönberger and Frahm for this step, and it treats SfM as the input stage rather than as its own contribution.
Check yourself
QuestionRecall: what does the epipolar constraint tell you about a point seen in two photos?Show answer
If a point is seen at in one photo and in another, then for normalised coordinates, where is the essential matrix. The matching point in the second photo must lie on a known line, so a search for it is one-dimensional.
QuestionComputation: in the triangulation example, a point is at with cameras one unit apart and focal length 1. What is the disparity?Show answer
and , so the disparity is .
QuestionWhy: why does bundle adjustment use pixel reprojection error rather than error in 3D space?Show answer
The measurements are pixels, so the residual is the difference between the observed and predicted pixel. Measuring in 3D would require knowing depth, which is the unknown being solved for. Pixel error is also comparable across cameras at different distances.
QuestionApplied: you reconstruct a scene from photos and the result is correct in shape but the room looks twice as big as it is. What is the most likely cause, and how would you fix it?Show answer
SfM recovers the scene only up to a similarity transform, so the overall scale is arbitrary. The fix is to fix the scale from a known measurement in the scene, such as a distance between two marked points, and rescale all cameras and points by the ratio of the true distance to the reconstructed one.
Sources
- Structure from motion, Wikipedia. https://en.wikipedia.org/wiki/Structure_from_motion
- COLMAP project page, Schönberger and Frahm. https://colmap.github.io/
- Kerbl et al., 3D Gaussian Splatting, 2023. https://arxiv.org/abs/2308.04079