Vision 3D articielle Session 1: Projective geometry, camera matrix, panorama

Similar documents
Lecture 2: Homogeneous Coordinates, Lines and Conics

(Quasi-)Newton methods

Epipolar Geometry. Readings: See Sections 10.1 and 15.6 of Forsyth and Ponce. Right Image. Left Image. e(p ) Epipolar Lines. e(q ) q R.

Geometric Camera Parameters

3D Scanner using Line Laser. 1. Introduction. 2. Theory

constraint. Let us penalize ourselves for making the constraint too big. We end up with a

(a) We have x = 3 + 2t, y = 2 t, z = 6 so solving for t we get the symmetric equations. x 3 2. = 2 y, z = 6. t 2 2t + 1 = 0,

= y y 0. = z z 0. (a) Find a parametric vector equation for L. (b) Find parametric (scalar) equations for L.

LINEAR ALGEBRA. September 23, 2010

5. Orthogonal matrices

Essential Mathematics for Computer Graphics fast

3. INNER PRODUCT SPACES

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

Inner Product Spaces

Factorization Theorems

Wii Remote Calibration Using the Sensor Bar

3. Let A and B be two n n orthogonal matrices. Then prove that AB and BA are both orthogonal matrices. Prove a similar result for unitary matrices.

Recall that two vectors in are perpendicular or orthogonal provided that their dot

Daniel F. DeMenthon and Larry S. Davis. Center for Automation Research. University of Maryland

2-View Geometry. Mark Fiala Ryerson University

Solutions to Math 51 First Exam January 29, 2015

Introduction to Algebraic Geometry. Bézout s Theorem and Inflection Points

LINEAR ALGEBRA W W L CHEN

Bildverarbeitung und Mustererkennung Image Processing and Pattern Recognition

Inner product. Definition of inner product

α = u v. In other words, Orthogonal Projection

Section 12.6: Directional Derivatives and the Gradient Vector

1 Determinants and the Solvability of Linear Systems

Relating Vanishing Points to Catadioptric Camera Calibration

Similarity and Diagonalization. Similar Matrices

Section 2.4: Equations of Lines and Planes

Projective Geometry: A Short Introduction. Lecture Notes Edmond Boyer

We shall turn our attention to solving linear systems of equations. Ax = b

The Characteristic Polynomial

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

Math 241, Exam 1 Information.

Orthogonal Diagonalization of Symmetric Matrices

CS3220 Lecture Notes: QR factorization and orthogonal transformations

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

1 Lecture: Integration of rational functions by decomposition

1 Review of Least Squares Solutions to Overdetermined Systems

THE FUNDAMENTAL THEOREM OF ALGEBRA VIA PROPER MAPS

Linear Algebra Notes

Chapter 6. Orthogonality

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Mathematics Course 111: Algebra I Part IV: Vector Spaces

THREE DIMENSIONAL GEOMETRY

1 3 4 = 8i + 20j 13k. x + w. y + w

Similar matrices and Jordan form

Applied Linear Algebra I Review page 1

DERIVATIVES AS MATRICES; CHAIN RULE

ISOMETRIES OF R n KEITH CONRAD

Build Panoramas on Android Phones

CURVE FITTING LEAST SQUARES APPROXIMATION

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

MATH 304 Linear Algebra Lecture 9: Subspaces of vector spaces (continued). Span. Spanning set.

General Framework for an Iterative Solution of Ax b. Jacobi s Method

Linear Algebra Review. Vectors

Linear Threshold Units

Section 13.5 Equations of Lines and Planes

160 CHAPTER 4. VECTOR SPACES

How To Solve A Linear Dierential Equation

Problems. Universidad San Pablo - CEU. Mathematical Fundaments of Biomedical Engineering 1. Author: First Year Biomedical Engineering

Introduction to the Finite Element Method (FEM)

SOLUTIONS. f x = 6x 2 6xy 24x, f y = 3x 2 6y. To find the critical points, we solve

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

INTRODUCTION TO RENDERING TECHNIQUES

The Steepest Descent Algorithm for Unconstrained Optimization and a Bisection Line-search Method

Equations Involving Lines and Planes Standard equations for lines in space

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

EXPERIMENTAL EVALUATION OF RELATIVE POSE ESTIMATION ALGORITHMS

5 Homogeneous systems

Computational Optical Imaging - Optique Numerique. -- Deconvolution --

Video stabilization for high resolution images reconstruction

Section 1.1. Introduction to R n

1 VECTOR SPACES AND SUBSPACES

Projective Geometry. Projective Geometry

Lecture 12: Cameras and Geometry. CAP 5415 Fall 2010

CONTROLLABILITY. Chapter Reachable Set and Controllability. Suppose we have a linear system described by the state equation

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

Math 4310 Handout - Quotient Vector Spaces

MATH 304 Linear Algebra Lecture 20: Inner product spaces. Orthogonal sets.

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Least-Squares Intersection of Lines

Continued Fractions and the Euclidean Algorithm

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

15. Symmetric polynomials

An Iterative Image Registration Technique with an Application to Stereo Vision

Principles of Scientific Computing Nonlinear Equations and Optimization

8. Linear least-squares

Finite cloud method: a true meshless technique based on a xed reproducing kernel approximation

Homogeneous systems of algebraic equations. A homogeneous (ho-mo-geen -ius) system of linear algebraic equations is one in which

University of Lille I PC first year list of exercises n 7. Review

A Flexible New Technique for Camera Calibration

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Solution of Linear Systems

Planar Curve Intersection

Lecture 14: Section 3.3

APPLICATIONS. are symmetric, but. are not.

x = + x 2 + x

Transcription:

Vision 3D articielle Session 1: Projective geometry, camera matrix, panorama Pascal Monasse monasse@imagine.enpc.fr IMAGINE, École des Ponts ParisTech

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

The pinhole camera model Projection (Source: Wikipedia) Thepinhole camera (French: sténopé): Model Ideal model with an aperture reduced to a single point. No account for blur of out of focus objects, nor for the lens geometric distortion.

Central projection in camera coordinate frame Rays from C are the same: Cx = λ CX In the camera coordinate frame CXYZ : x X y = λ Y f Z Thus λ = f /Z and ( x y ) = f ( X /Z Y /Z ) In pixel coordinates: ( ) ( ) ( ) u αx + cx (αf )X /Z + cx = = v αy + c y (αf )Y /Z + c y αf : focal length in pixels, (c x, c y ): position of principal point P in pixels.

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Projective plane We identify two points of R 3 on the same ray from the origin through the equivalence relation: R : xry λ 0 : x = λy Projective plane: P 2 = (R 3 \ O)/R Point ( ) ( x y z = x/z y/z 1 ) if z 0. The point ( x/ɛ y/ɛ 1 ) = ( x y ɛ ) is a point far away in the ( direction of the line of slope y/x. The limit value x y 0 ) is the innite point in this direction. Given a plane of R 3 through O, of equation ax + by + cz = 0. It corresponds to a line in P 2 represented in homogeneous coordinates by ( a b c). Its equation is: ( ) ( T a b c X Y Z) = 0.

Projective plane Line through points x 1 and x 2 : l = x 1 x 2 since (x 1 x 2 ) T x i = x 1 x 2 x i = 0 Intersection of two lines l 1 and l 2 : x = l 1 l 2 since l T i (l 1 l 2 ) = l i l 1 l 2 = 0 Line at innity: 0 x l = 0 since l T y = 0 1 0 Intersection of two parallel lines: a a b b b = (c 2 c 1 ) a l 0 c 1 c 2

Calibration matrix Let us get back to the projection equation: ( ) ( ) u fx /Z + cx = = 1 ( ) fx + cx Z v fy /Z + c y Z fy + c y Z (replacing αf by f ) We rewrite: Z u v 1 := x = f c x f c y 1 X Y Z The 3D point being expressed in another orthonormal coordinate frame: X f c x x = f c y ( ) R T Y Z 1 1

Calibration matrix The (internal) calibration matrix (3 3) is: f c x K = f c y 1 The projection matrix (3 4) is: ( P = K R ) T If pixels are trapezoids, we can generalize K : K = f x s c x f y c y (with s = f x cotan θ) 1 Theorem Let P be a 3 4 matrix whose left 3 3 sub-matrix is invertible. There is a unique decomposition P = K Proof: Gram-Schmidt on rows of left sub-matrix of P starting from last row (RQ decomposition), then T = K 1 P 4. ( R T ).

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Homographies Let us see what happens when we take two pictures in the following particular cases: 1. Rotation around the optical center (and maybe change of internal parameters). x = K RK 1 x := Hx 2. The world is at. We observe the plane Z = 0: X x ( ) = K R 1 R 2 R 3 T Y 0 = ) (R K 1 R 2 T x := Hx 1 In both cases, we deal with a 3 3 invertible matrix H, a homography. Property: a homography preserves alignment. If x 1, x 2, x 3 aligned, then Hx 1 Hx 2 Hx 3 = H x 1 x 2 x 3 = 0 are

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Panorama construction We stitch together images by correcting homographies. This assumes that the scene is at or that we are rotating the camera. Homography estimation: λx = Hx x (Hx) = 0, which amounts to 2 independent linear equations per correspondence (x, x ). 4 correspondences are enough to estimate H (but more can be used to estimate through mean squares minimization). Panorama from 14 photos

Algebraic error minimization x i (Hx i) = 0 is a system of three linear equations in H. We gather the unkwown coecients of H in a vector of 9 rows h = ( H 11 H 12... H 33 ) T We write the equations as A i h = 0 with ( xi y i 1 0 0 0 x x i i x y i i x i A i = 0 0 0 x i y i 1 y x i i y y i i y i x i y y i i y y x x i i i i x y i i x 0 0 0 i We can discard the third line and stack the dierent A i in A. h is a vector of the kernel of A (8 9 matrix) We can also suppose H 3,3 = h 9 = 1 and solve ) A :,1:8 h 1:8 = A :,9

Geometric error When we have more than 4 correspondences, we minimize the algebraic error ɛ = x (Hx i i) 2, i but it has no geometric meaning. A more signicant error is geometric: Image 1 Hx H d Image 2 x x d 1 H x H 1 Either d 2 = d(x, Hx) 2 (transfer error) or d 2 + d 2 = d(x, H 1 x ) 2 + d(x, Hx) 2 (Symmetric transfer error)

Gold standard error Actually, we can consider x and x as noisy observations of ground truth positions ^x and ^x = H^x. Image 1 H Hx d Image 2 x x d ^x ^ ɛ(h,^x) = d(x,^x) 2 + d(x, H^x) 2 Problem: this has a lot of parameters: H, {^x i } i=1...n

Sampson error A method that linearizes the dependency on ^x in the gold standard error so as to eliminate these unknowns. 0 = ɛ(h,^x) = ɛ(h, x) + J(^x x) with J = ɛ (H, x) x Find ^x minimizing x ^x 2 subject to J(x ^x) = ɛ Solution: x ^x = J T (JJ T ) 1 ɛ and thus: x ^x 2 = ɛ T (JJ T ) 1 ɛ (1) Here, ɛ i = A i h = x i (Hx i) is a 3-vector. For each i, there are 4 variables (x i, x ), so J is 3 4. i This is almost the algebraic error ɛ T ɛ but with adapted scalar product. The resolution, through iterative method, must be initialized with the algebraic minimization.

Applying homography to image Two methods: 1. push pixels to transformed image and round to the nearest pixel center. 2. pull pixels from original image by interpolation. Image 1 H push H(Image 1) pull H 1

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Camera calibration by resection [R.Y. Tsai,An ecient and accurate camera calibration technique for 3D machine vision, CVPR'86] We estimate the camera internal parameters from a known rig, composed of 3D points whose coordinates are known. We have points X i and their projection x i in an image. In homogeneous coordinates: x i = PX i or the 3 equations (but only 2 of them are independent) x i (PX i ) = 0 Linear system in unknown P. There are 12 parameters in P, we need 6 points in general (actually only 5.5). Decomposition of P allows nding K. Restriction: The 6 points cannot be on a plane, otherwise we have a degenerate situation; in that case, 4 points dene the homography and the two extra points yield no additional constraint.

Calibration with planar rig [Z. Zhang A exible new technique for camera calibration 2000] Problem: One picture is not enough to nd K. Solution: Several snapshots are used. For each one, we determine the homography H between the rig and the image. The homography being computed with an arbitrary multiplicative factor, we write ( ) λh = K R 1 R 2 T We rewrite: λk 1 H = λ ( K 1 H 1 K 1 H 2 ) K 1 H 3 = (R 1 R 2 ) T 2 equations expressing orthonormality of R 1 and R 2 : H T 1 (K T K 1 )H 1 = H T 2 (K T K 1 )H 2 H T 1 (K T K 1 )H 2 = 0 With 3 views, we have 6 equations for the 5 parameters of K T K 1 ; then Cholesky decomposition.

The problem of geometric distortion At small or moderate focal length, we cannot ignore the geometric distortion due to lens curvature, especially away from image center. This is observable in the non-straightness of certain lines: Photo: 5600 3700 pixels Deviation of 30 pixels The classical model of distortion is radial polynomial: ( ) ( ) ( ) xd dx = (1 + a 1 r 2 + a 2 r 4 x dx +... ) d y y d y y d

Estimation of geometric distortion If we integrate distortion coecients as unknowns, there is no more closed formula estimating K. We have a non-linear minimization problem, which can be solved by an iterative method. To initialize the minimization, we assume no distortion (a 1 = a 2 = 0) and estimate K with the previous linear procedure.

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Linear least squares problem For example, when we have more than 4 point correspondences in homography estimation: A m 8 h = B m m 8 In the case of an overdetermined linear system, we minimize ɛ(x) = AX B 2 = f (X) 2 The gradient of ɛ can be easily computed: ɛ(x) = 2(A T AX A T B) The solution is obtained by equating the gradient to 0: X = (A T A) 1 A T B Remark 1: this is correct only if A T A is invertible, that is A has full rank. Remark 2: if A is square, it is the standard solution X = A 1 B Remark 3: A ( 1) = (A T A) 1 A T is called the pseudo-inverse of A, because A ( 1) A = I n.

Non-linear least squares problem We would like to solve as best we can f (X) = 0 with f non-linear. We thus minimize ɛ(x) = f (X) 2 Let us compute the gradient of ɛ: ɛ(x) = 2J T f (X) with J ij = f i Gradient descent: we iterate until convergence X = αj T f (X), α > 0 When we are close to the minimum, a faster convergence is obtained by Newton's method: x j ɛ(x 0 ) ɛ(x) + ɛ(x) T ( X) + ( X) T ( 2 ɛ)( X) and minimum is for X = ( 2 ɛ) 1 ɛ

Levenberg-Marquardt algorithm This is a mix of gradient descent and quasi-newton method (quasi since we do not compute explictly the Hessian matrix, but approximate it). The gradient of ɛ is ɛ(x) = 2J T f (X) so the Hessian matrix of ɛ is composed of sums of two terms: 1. Product of rst derivatives of f. 2. Product of f and second derivatives of f. The idea is to ignore the second terms, as they should be small when we are close to the minimum (f 0). The Hessian is thus approximated by Levenberg-Marquardt iteration: H = 2J T J X = (J T J + λi ) 1 J T f (X), λ > 0

Levenberg-Marquardt algorithm Principle: gradient descent when we are far from the solution (λ large) and Newton's step when we are close (λ small). 1. Start from initial X and λ = 10 3. 2. Compute X = (J T J + λi ) 1 J T f (X), λ > 0 3. Compare ɛ(x + X) and ɛ(x): 3a If ɛ(x + X) ɛ(x), nish. 3b If ɛ(x + X) < ɛ(x), X X + X λ λ/10 3c If ɛ(x + X) > ɛ(x), λ 10λ 4. Go to step 2.

Example of distortion correction Results of Zhang: Snapshot 1 Snapshot 2

Example of distortion correction Results of Zhang: Corrected image 1 Corrected image 2

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Conclusion Camera matrix K (3 3) depends only on internal parameters of the camera. Projection matrix P (3 4) depends on K and position/orientation. Homogeneous coordinates are convenient as they linearize the equations. A homography between two images arises when the observed scene is at or the principal point is xed. 4 or more correspondences are enough to estimate a homography (in general)

Contents Pinhole camera model Projective geometry Homographies Panorama Internal calibration Optimization techniques Conclusion Practical session

Practical session: panorama construction Objective: the user clicks 4 or more corresponding points in left and right images. After a right button click, the program computes the homography and shows the resulting panorama in a new window. Install Imagine++ (http://imagine.enpc.fr/~monasse/imagine++/) on your machine. Let the user click the matching points. Build the linear system to solve Ax = b; use linsolve (in LinAlg) to nd the solution x. Compute the bounding box of the panorama. Stitch the images: on overlapping area, take the average of colors at corresponding pixels in both images.