Unknowns and measurements
Suppose cameras observe points, and every point is visible in every image. Each observation is a pixel, so it gives two numbers, and there are of them. The unknowns are three coordinates per point and six pose parameters per camera (three for rotation, three for translation), so in total. Not all of these unknowns can be determined. If you rotate, translate and scale the whole scene together with the cameras, every image stays exactly the same. That freedom has seven degrees: three for rotation, three for translation and one for scale. It is called the gauge freedom. The images can only fix the reconstruction up to such a similarity transform, so the problem has a chance of being determined when Two cameras and five points give , which is why five correspondences are the minimum for the relative pose of two calibrated cameras. In practice you have thousands of points and many cameras, so the system is heavily overdetermined, and the work goes into finding correct correspondences and solving a large nonlinear least-squares problem. You will fix the gauge yourself: the first camera sits at the origin with the identity rotation, and the scale is whatever the first two views give. At the end, a similarity transform maps your reconstruction onto COLMAP’s.Code
Code
The scene
The photos are the garden scene of the Mip-NeRF 360 dataset: 185 photos taken while walking around a table in a garden. You use the copies downsampled by a factor of eight, about pixels. The dataset also ships a COLMAP reconstruction of the full set, made by the dataset’s authors and not rerun here, as three binary files:cameras.bin holds the intrinsics, images.bin the pose of each photo and the pixels it observed, and points3D.bin the sparse points with their colors. The reader below parses them, so you can compare against them later.
Code
Code
Code
Code
Features and matches
Structure from motion needs pixels in different photos that show the same 3D point. You find them in two steps, as Chapter 44 of the book describes. An interest point detector picks distinctive locations, such as corners and blobs, at several scales. A descriptor then summarizes the patch around each location as a vector that changes little with viewpoint and lighting. Here the detector and descriptor are SIFT: each keypoint gets a 128-dimensional histogram of gradient orientations. Two keypoints match when their descriptors are close. A nearest-neighbor match alone is unreliable on repeated texture such as grass and leaves, where many patches look alike. The ratio test keeps a match only when the nearest descriptor is clearly closer than the second nearest, here by a factor of . Matches that pass can still be wrong, and the geometry below removes most of the rest.Code
Code
The essential matrix
Place the first camera at the origin, so a point has coordinates in its frame, and the second camera at rotation and translation , so the same point has coordinates there. The normalized image points are and . The three vectors , and all lie in one plane, the epipolar plane through the two camera centers and the point. Three coplanar vectors have a zero triple product: Write the cross product with as multiplication by the skew-symmetric matrix . The constraint becomes is the essential matrix. It is defined only up to scale, because can be scaled without changing the constraint, so it has five degrees of freedom: three for and two for the direction of . A valid essential matrix has two equal singular values and a third that is zero. In pixel coordinates the same constraint reads with the fundamental matrix . For one point in the first image, is a line in the second image, the epipolar line, and the match must lie on it.Estimating E with RANSAC
Each correspondence gives one equation that is linear in the nine entries of . Stack eight of them into an matrix and take the null vector of (the right singular vector with the smallest singular value). This is the eight-point algorithm. Afterwards you project the result onto the set of valid essential matrices by replacing its singular values with . The five-point algorithm uses the minimum of five correspondences and is what production systems run, but it needs a polynomial solver; eight points keep everything linear (Hartley & Zisserman, 2004). Some matches are wrong, and one wrong match ruins a least-squares fit. RANSAC handles this by repetition. Draw eight random matches, fit , and count how many of all the matches agree with it within a threshold. Keep the with the most agreement, then refit it on all of its inliers. The agreement test below is the Sampson distance, a first-order approximation of the distance in pixels from a match to its epipolar lines.Code
Code
Relative pose and triangulation
Factor with . The rotation is or , and the translation direction is , the last column of (Hartley & Zisserman, 2004). That gives four candidate poses. Only one of them puts the scene in front of both cameras; the other three place the points behind one camera or both. So you triangulate the inliers with each candidate and keep the pose with the most points at positive depth in both views. This is the cheirality check. Triangulation intersects two viewing rays. With projection matrices and and the homogeneous point , the constraint gives two independent linear equations per view: where is the -th row of . Stack the four equations of the two views and take the null vector. This is the direct linear transform (DLT). Noise means the two rays do not quite meet, and the DLT returns a point close to both.Code
Code
Reprojection error and bundle adjustment
The linear steps above minimize algebraic quantities that have no direct meaning in the image. The quantity you care about is the reprojection error: project each 3D point into every camera that saw it and measure the distance in pixels to the observed keypoint. With the projection followed by , camera predicts point at Bundle adjustment minimizes the total reprojection error over all poses and points together (Triggs et al., 2000): where is the set of observations. The name comes from the bundles of rays that leave each camera and are adjusted until they pass through the points. Three details make the problem solvable in practice:- Each rotation is stored as an axis-angle vector , with given by the Rodrigues formula. Three unconstrained numbers keep a rotation during the optimization.
- is the Huber loss, quadratic for small residuals and linear for large ones, so a few remaining bad matches cannot dominate.
- The first camera stays fixed at the origin. That removes six of the seven gauge degrees of freedom; the scale stays at the one set by the first two views.
Code
Code
Two-view initialization
The reconstruction starts from views 0 and 2. Each inlier match becomes a 3D point with two observations, and every observation remembers which keypoint it came from, so later views can find it. Points that triangulate behind a camera, or from rays that are almost parallel, are dropped: a small angle between the rays makes depth very uncertain.Code
Code
Adding views
Each new photo is registered against the points you already have. Match it to the registered views, and every match whose keypoint already belongs to a 3D point gives a 2D-to-3D correspondence. Finding a camera pose from such correspondences is the perspective-n-point problem (PnP). RANSAC again separates good correspondences from bad ones. Then the matches that do not yet have a point are triangulated against the registered view they match, which adds new points, and bundle adjustment refines all poses and points together. This is incremental structure from motion, the strategy COLMAP uses. Global methods instead estimate all rotations and translations at once from the pairwise relative poses and refine them afterwards (Pan et al., 2024). After each bundle adjustment, observations with a reprojection error above four pixels are removed, so wrong matches that survived RANSAC do not accumulate.Code
Code
Comparison with COLMAP
The dataset’s authors reconstructed all 185 photos with COLMAP, which runs the same pipeline in a more careful form (Schonberger2016-xn). Its poses serve as the reference here. Structure from Motion at Scale runs COLMAP itself on these twelve photos and lines up each of its stages with the steps above. Your reconstruction and COLMAP’s live in different gauges, with different origin, orientation and scale. To compare them you find the similarity transform that best maps your camera centers onto COLMAP’s centers . The least-squares solution has a closed form (the Umeyama method). Center both sets, take the SVD of their cross-covariance , and set where makes , and is the mean squared distance of the from their centroid.Code
Code
What the reconstruction hands on
The three files are the output of structure from motion, and Structure from Motion at Scale describes their format and conventions. They are also the input of the two radiance field methods in this chapter:cameras.bin: the intrinsics of each camera model.images.bin: for every photo, its rotation (as a quaternion) and translation, plus the keypoints it contributed.points3D.bin: the sparse points, each with a color, a mean reprojection error and the list of photos that saw it.
Code
Code
References
- Hartley, R., Zisserman, A. (2004). Multiple View Geometry in Computer Vision.
- Pan, L., Baráth, D., Pollefeys, M., Schönberger, J. (2024). Global Structure-from-Motion Revisited. arXiv [cs.CV]. Link
- Triggs, B., Mc Lauchlan, P., Hartley, R., Fitzgibbon, A. (2000). Bundle Adjustment — A Modern Synthesis. Plan. Perspect. Link
Found an error on this page? Report an issue.

