2Slide credit: Noah Snavely Structure from motionGiven a set of corresponding points in two or more images, compute the camera parameters and the 3D point coordinates?Structure from motion solves the following problem:Given a set of images of a static scene with 2D points in correspondence, shown here as color-coded points, find…a set of 3D points P anda rotation R and position t of the cameras that explain the observed correspondences. In other words, when we project a point into any of the cameras, the reprojection error between the projected and observed 2D points is low.This problem can be formulated as an optimization problem where we want to find the rotations R, positions t, and 3D point locations P that minimize sum of squared reprojection errors f. This is a non-linear least squares problem and can be solved with algorithms such as Levenberg-Marquart. However, because the problem is non-linear, it can be susceptible to local minima. Therefore, it’s important to initialize the parameters of the system carefully. In addition, we need to be able to deal with erroneous correspondences.?Camera 1?Camera 3Camera 2?R1,t1R3,t3R2,t2Slide credit: Noah Snavely
3Structure from motion Given: m images of n fixed 3D points λij xij = Pi Xj , i = 1, … , m, j = 1, … , nProblem: estimate m projection matrices Pi and n 3D points Xj from the mn correspondences xijx1jx2jx3jXjP1P2P3
4Is SfM always uniquely solvable? Necker cubeSource: N. Snavely
5Structure from motion ambiguity If we scale the entire scene by some factor k and, at the same time, scale the camera matrices by the factor of 1/k, the projections of the scene points in the image remain exactly the same:It is impossible to recover the absolute scale of the scene!
6Structure from motion ambiguity If we scale the entire scene by some factor k and, at the same time, scale the camera matrices by the factor of 1/k, the projections of the scene points in the image remain exactly the sameMore generally, if we transform the scene using a transformation Q and apply the inverse transformation to the camera matrices, then the images do not change:
7Types of ambiguityProjective15dofPreserves intersection and tangencyAffine12dofPreserves parallellism, volume ratiosSimilarity7dofPreserves angles, ratios of lengthEuclidean6dofPreserves angles, lengthsWith no constraints on the camera calibration matrix or on the scene, we get a projective reconstructionNeed additional information to upgrade the reconstruction to affine, similarity, or Euclidean
17Projection of world origin Affine camerasA general affine camera combines the effects of an affine transformation of the 3D space, orthographic projection, and an affine transformation of the image:Affine projection is a linear mapping + translation in non-homogeneous coordinatesxXa1a2Projection of world origin
18Affine structure from motion Given: m images of n fixed 3D points:xij = Ai Xj + bi , i = 1,… , m, j = 1, … , nProblem: use the mn correspondences xij to estimate m projection matrices Ai and translation vectors bi, and n points XjThe reconstruction is defined up to an arbitrary affine transformation Q (12 degrees of freedom):We have 2mn knowns and 8m + 3n unknowns (minus 12 dof for affine ambiguity)Thus, we must have 2mn >= 8m + 3n – 12For two views, we need four point correspondences
19Affine structure from motion Centering: subtract the centroid of the image points in each viewFor simplicity, set the origin of the world coordinate system to the centroid of the 3D pointsAfter centering, each normalized 2D point is related to the 3D point Xj by
20Affine structure from motion Let’s create a 2m × n data (measurement) matrix:cameras (2 m)points (n)C. Tomasi and T. Kanade. Shape and motion from image streams under orthography: A factorization method. IJCV, 9(2): , November 1992.
21Affine structure from motion Let’s create a 2m × n data (measurement) matrix:points (3 × n)cameras (2 m × 3)The measurement matrix D = MS must have rank 3!C. Tomasi and T. Kanade. Shape and motion from image streams under orthography: A factorization method. IJCV, 9(2): , November 1992.
22Factorizing the measurement matrix Source: M. Hebert
23Factorizing the measurement matrix Singular value decomposition of D:Source: M. Hebert
24Factorizing the measurement matrix Singular value decomposition of D:Source: M. Hebert
25Factorizing the measurement matrix Obtaining a factorization from SVD:Source: M. Hebert
26Factorizing the measurement matrix Obtaining a factorization from SVD:This decomposition minimizes |D-MS|2Source: M. Hebert
27Affine ambiguityThe decomposition is not unique. We get the same D by using any 3×3 matrix C and applying the transformations M → MC, S →C-1SThat is because we have only an affine transformation and we have not enforced any Euclidean constraints (like forcing the image axes to be perpendicular, for example)Source: M. Hebert
28Eliminating the affine ambiguity Transform each projection matrix A to another matrix AC to get orthographic projectionImage axes are perpendicular and scale is 1This translates into 3m equations:(AiC)(AiC)T = Ai(CCT)Ai = Id, i = 1, …, mSolve for L = CCTRecover C from L by Cholesky decomposition: L = CCTUpdate M and S: M = MC, S = C-1Sa1 · a2 = 0|a1|2 = |a2|2 = 1xAAT = Ida2Xa1Source: M. Hebert
29Reconstruction results C. Tomasi and T. Kanade. Shape and motion from image streams under orthography: A factorization method. IJCV, 9(2): , November 1992.
30Algorithm summary Given: m images and n features xij For each image i, center the feature coordinatesConstruct a 2m × n measurement matrix D:Column j contains the projection of point j in all viewsRow i contains one coordinate of the projections of all the n points in image iFactorize D:Compute SVD: D = U W VTCreate U3 by taking the first 3 columns of UCreate V3 by taking the first 3 columns of VCreate W3 by taking the upper left 3 × 3 block of WCreate the motion and shape matrices:M = U3W3½ and S = W3½ V3T (or M = U3 and S = W3V3T)Eliminate affine ambiguitySource: M. Hebert
31Dealing with missing data So far, we have assumed that all points are visible in all viewsIn reality, the measurement matrix typically looks something like this:cameraspoints
32Dealing with missing data Possible solution: decompose matrix into dense sub-blocks, factorize each sub-block, and fuse the resultsFinding dense maximal sub-blocks of the matrix is NP-complete (equivalent to finding maximal cliques in a graph)Incremental bilinear refinementPerform factorization on a dense sub-block(2) Solve for a new 3D point visible by at least two known cameras (linear least squares)(3) Solve for a new camera that sees at least three known 3D points (linear least squares)F. Rothganger, S. Lazebnik, C. Schmid, and J. Ponce. Segmenting, Modeling, and Matching Video Clips Containing Multiple Moving Objects. PAMI 2007.
33Projective structure from motion Given: m images of n fixed 3D pointsλij xij = Pi Xj , i = 1,… , m, j = 1, … , nProblem: estimate m projection matrices Pi and n 3D points Xj from the mn correspondences xijx1jx2jx3jXjP1P2P3
34Projective structure from motion Given: m images of n fixed 3D pointsλij xij = Pi Xj , i = 1,… , m, j = 1, … , nProblem: estimate m projection matrices Pi and n 3D points Xj from the mn correspondences xijWith no calibration info, cameras and points can only be recovered up to a 4x4 projective transformation Q:X → QX, P → PQ-1We can solve for structure and motion when2mn >= 11m +3n – 15For two cameras, at least 7 points are needed
35Projective SFM: Two-camera case Compute fundamental matrix F between the two viewsFirst camera matrix: [I | 0]Second camera matrix: [A | b]Then b is the epipole (FTb = 0), A = –[b×]FF&P sec
36Sequential structure from motion Initialize motion from two images using fundamental matrixInitialize structure by triangulationFor each additional view:Determine projection matrix of new camera using all the known 3D points that are visible in its image – calibrationpointscameras
37Sequential structure from motion Initialize motion from two images using fundamental matrixInitialize structure by triangulationFor each additional view:Determine projection matrix of new camera using all the known 3D points that are visible in its image – calibrationRefine and extend structure: compute new 3D points, re-optimize existing points that are also seen by this camera – triangulationpointscameras
38Sequential structure from motion Initialize motion from two images using fundamental matrixInitialize structure by triangulationFor each additional view:Determine projection matrix of new camera using all the known 3D points that are visible in its image – calibrationRefine and extend structure: compute new 3D points, re-optimize existing points that are also seen by this camera – triangulationRefine structure and motion: bundle adjustmentpointscameras
39Bundle adjustment Non-linear method for refining structure and motion Minimizing reprojection errorXjP1Xjx3jx1jP3XjP2Xjx2jP1P3P2
40Self-calibrationSelf-calibration (auto-calibration) is the process of determining intrinsic camera parameters directly from uncalibrated imagesFor example, when the images are acquired by a single moving camera, we can use the constraint that the intrinsic parameter matrix remains fixed for all the imagesCompute initial projective reconstruction and find 3D projective transformation matrix Q such that all camera matrices are in the form Pi = K [Ri | ti]Can use constraints on the form of the calibration matrix: zero skewCan use vanishing points
41Modern SFM pipelineHere’s how the same set of photos appear in our photo explorer. Our system takes the set of photos and automatically determines the relative positions and orientations from which each photo was taken. We can then load the photos into our immersive 3D browser where the user can visualize and explore the photos using spatial relationships.N. Snavely, S. Seitz, and R. Szeliski, "Photo tourism: Exploring photo collections in 3D," SIGGRAPH 2006.
42Feature detection Detect features using SIFT [Lowe, IJCV 2004] So, we begin by detecting SIFT features in each photo.[We detect SIFT features in each photo, resulting in a set of feature locations and 128-byte feature descriptors…]Source: N. Snavely
43Feature detection Detect features using SIFT [Lowe, IJCV 2004] Source: N. Snavely
44Feature matching Match features between each pair of images Next, we match features across each pair of photos using approximate nearest neighbor matching.Source: N. Snavely
45Use RANSAC to estimate fundamental matrix between each pair Feature matchingUse RANSAC to estimate fundamental matrix between each pairThe matches are refined by using RANSAC, which is a robust model-fitting technique, to estimate a fundamental matrix between each pair of matching images and keeping only matches consistent with that fundamental matrix.We then link connected components of pairwise feature matches together to form correspondences across multiple images.Once we have correspondences, we run structure from motion to recover the camera and scene geometry. Structure from motion solves the following problem:Source: N. Snavely
46Image connectivity graph (graph layout produced using the Graphviz toolkit:Source: N. Snavely
47Incremental SFMPick a pair of images with lots of inliers (and preferably, good EXIF data)Initialize intrinsic parameters (focal length, principal point) from EXIFEstimate extrinsic parameters (R and t)Five-point algorithmUse triangulation to initialize model pointsWhile remaining images existFind an image with many feature matches with images in the modelRun RANSAC on feature matches to register new image to modelTriangulate new pointsPerform bundle adjustment to re-optimize everything
48The devil is in the details Handling degenerate configurations (e.g., homographies)Eliminating outliersDealing with repetitions and symmetriesHandling multiple connected componentsClosing loops….
49Review: Structure from motion AmbiguityAffine structure from motionFactorizationDealing with missing dataIncremental structure from motionProjective structure from motionBundle adjustmentModern structure from motion pipeline
50Summary: 3D geometric vision Single-view geometryThe pinhole camera modelVariation: orthographic projectionThe perspective projection matrixIntrinsic and extrinsic parametersCalibrationSingle-view metrology, calibration using vanishing pointsMultiple-view geometryTriangulationThe epipolar constraintEssential matrix and fundamental matrixStereoBinocular, multi-viewStructure from motionReconstruction ambiguityAffine SFMProjective SFM