Computer Vision I -
Algorithms and Applications:
Two-View Geometry
Carsten Rother
03/12/2013
This is the lecture with most math
β¦ for any error on slides please contact:
v
Roadmap: matching 2 Images (appearance & geometry)
β’ Find interest points (including different scales)
β’ Find orientated patches around interest points to capture appearance
β’ Encode patch in a descriptor
β’ Find matching patches according to appearance (similar descriptors)
β’ Verify matching patches according to geometry
The tasks for this lecture
β’ Two-view transformations we look at today:
β’ Homography π»: between two views
β’ Camera matrix π (mapping from 3D to 2D)
β’ Fundamental matrix πΉ between two un-calibrated views
β’ Essential matrix πΈ between two calibrated views
β’ Derive geometrically: π», π, πΉ, πΈ , i.e. what do they mean?
β’ Calibration: Take primitives (points, lines, planes, cones,β¦) to compute π», π, πΉ, πΈ :
β’ What is the minimal number of points to compute them (very important for next lecture on robust methods)
β’ If we have many points with noise: what is the best way to computer them: algebraic error versus geometric error ?
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from π», π, πΉ, πΈ?
β’ What can we do with π», π, πΉ, πΈ? (e.g. augmented reality)
Singular Value Decomposition (SVD)
β’ Reminder: separable filters
Apply SVD to the kernel matrix:
Note:
β π₯ β β π¦
β π₯ β π¦ β π₯
β π¦
Properties of SVD
β’ In short: π΄ = ππ·π
πβ’ If π΄ = π Γ π with π β₯ π then π = π Γ π , D = n Γ π, π = π Γ π
β’ If π΄ = π Γ π with π < π then add zero-valued rows to A to make it π Γ π
β’ π and π form an orthogonal basis: π
ππ = π
ππ = πΌ
πΓπβ’ It is: ππ₯ = π₯ (an example U is a rotation matrix)
β’ Implementation: π΄ = π Γ π needs: 4π
2π + 8ππ
2+ 9π
3[Golub-89]
β’ It is: π΄
ππ΄ = ππ·π
πππ·π
π= ππ·
2π
πthen the entries of π·
2are eigenvalues of π΄
ππ΄ and eigenvectors are columns of π
Singular values; sorted: π
πβ₯ π
π+1Null space (correction from last lecture)
β’ Right null space: π΄ π = π where π΄ = π Γ π with π < π this is given by the (n-m) last column vectors in π
β’ Example:
A =
1 2
β1 2
β1 2
β1 2
1 2
1 2
Then SVD is:
1 2
β1
β2
β1
β1 2 2
1
β2 1
0 0 02
=
1
β2
β1
β2 0
β1
β2 1
β2 0 0 0 1
1 0 0 0 1 0 0 0 0
1
β2 0 β1β2 0 1 0
β1
β2 0 β1β2
1
β2 0 β1 0 1 β20 0 0 0
π = π
β1
β2 0
β1
β2
= π 1 0 1
Nullspace
and π΄π₯ = 0
Least Square Problem (homogenous linear system)
β’ Find a solution to π΄π = 0 where π΄ = π Γ π with π β₯ π
β’ Solution π = 0 is not interesting
β’ If π is solution then any ππ. So we look for π = 1
β’ π΄π = 0 is never exactly zero (due to noise in measurements).
Hence, solve in least square sense:
π β = ππππππ π π΄π subject to π = π
β’ π β is the last column of π, where π΄ = ππ·π π
(blackboard)
Proof
Topic 1: Homography π»
β’ Derive geometrically π»
β’ Calibration: Take measurements (points) to compute π»
β’ How do we do that with a minimal number of points?
β’ How do we do that with many points?
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from π»?
β’ What can we do with π» ?
Definition Homography
β’ Definition: A projectivity (or homography) β is an invertible mapping β from π
2to π
2such that three points π₯
1, π₯
2, π₯
3lie on the same line if an only if β(π₯
1), β(π₯
2), β(π₯
3) do.
β’ Theorem: A mapping β from π
2to π
2is a homography if and only if there exists a non-singular 3 Γ 3 matrix H with β(π₯) = π»π₯
β’ In equations: xβ² = π»π₯
β’ π» has 8 DoF
π₯ π¦ 1
Transformation matrix π» β
11β
12β
13β
21β
22β
23β
31β
32β
33π¦β²π₯β²
1
=
Definition Homography
β’ Definition: A projectivity (or homography) β is an invertible mapping β from π
2to π
2such that three points π₯
1, π₯
2, π₯
3lie on the same line if an only if β(π₯
1), β(π₯
2), β(π₯
3) do.
β’ Theorem: A mapping β from π
2to π
2is a homography if and only if there exists a non- singular 3 Γ 3 matrix H with β π₯ = π»π₯
One direction of proof:
β’ If π₯
1, π₯
2, π₯
3lie on a line π then π
ππ₯
π= 0.
β’ Let H be a non-singular 3 Γ 3 matrix. Then π
ππ»
β1π»π₯
π= 0. Hence the points: π»π₯
πlie
on a transformed line π
β²= π
ππ»
β1Geometric Derivation: Homography
π₯ π¦ 1
Transformation matrix π» β
11β
12β
13β
21β
22β
23β
31β
32β
33π₯β²π¦β²
1
=
Mapping via a plane
Notation: x (homogenous 2D), x (inhomogenous 2D), πΏ (homogenous 3D), πΏ(inhomogenous 3D)
Homography from a rotating camera
Put it toghter: π
π= π²
ππΉπ²
πβππ
πHence π― = π²
ππΉπ²
πβπis a homography (general 3x3 matrix) with 8 DoF
~
π² = π 0 ππ π π π
π¦π₯0 0 1
π = π² πΉ (π°
πΓπ| β πͺ) πΏ
Camera 0: π
π= π²
ππΏ (in 3D βΆ π²
πβππ
π= πΏ) Camera 1: π
π= π²
ππΉ πΏ
~
~
~
~
~
Homography of a projection via a plane
(See geometric derivation on page 49)
Definition: A projectivity (or homography) β is an invertible mapping β from π
2to π
2such that three points π₯
1, π₯
2, π₯
3lie on the same line if an only if β(π₯
1), β(π₯
2), β(π₯
3) do so.
We know (see Theorem): All Homographies can be written as β(π₯) = π»π₯
We see visually that lines map to lines
So we can write: π₯
2= π»π₯
1How to compute/calibrate π»
β’ We have ππ₯β² = π»π₯
β’ H has 8 DoF
β’ We get for each pair of matching points (π₯β², π₯) the 3 equations:
1) β
11π₯
1+ β
12π₯
2+ β
13π₯
3= ππ₯
1β²2) β
21π₯
1+ β
22π₯
2+ β
23π₯
3= ππ₯
2β²β’ This gives 2 linear independent equations be taking the ratios.
Here 1) divide by 2) gives:
3) β
31π₯
1+ β
32π₯
2+ β
33π₯
3= ππ₯
3β²
π₯
1π₯
2β², π₯
2π₯
2β², π₯
3π₯
2β², βπ₯
1π₯
1β², βπ₯
2π₯
1β², βπ₯
3π₯
1β²β
11, β
12, β
13, β
21, β
22, β
23 π= 0
How to compute/calibrate π»
β
11β
12β
13β
21β
22β
23β
31β
32β
33= 0
β’ Put it together:
β’ We need a minimum of 4 points to get π΄β = 0 with π΄ ππ 8 Γ 9 matrix, and β ππ 9 Γ 1 vector
β’ Solution for β is the right null space of π΄ (This solution will be useful in next lecture)
π₯
1π₯
2β²π₯
2π₯
2β²π₯
3π₯
2β²βπ₯
1π₯
1β²βπ₯
2π₯
1β²βπ₯
3π₯
1β²0 0 0 0 0 0 π₯
1π₯
3β²π₯
2π₯
3β²π₯
3π₯
3β²βπ₯
1π₯
2β²βπ₯
2π₯
2β²βπ₯
3π₯
2β².
. .
Often we have many, slightly wrong point-matches
image
Algorithm:
1) Take π β₯ 4 point matches (π₯, π₯β) 2) Assemble A with Ah = 0
3) compute π β = ππππππ β π΄π subject to π = π, use SVD to do this.
We know how to do: π β = ππππππ π π΄π subject to π = π
A more numerically stable solution
β’ Coefficients of an equation system should be in the same order of magnitude so as not to lose significant digits
β’ In pixels: π₯
ππ₯
πβ ~ 1π6
β’ Conditioning: scale and shift points to be in [-1..1] (or +/- β2 )
β’ A general rule, not only for homography computation
β’ How to do it:
A more numerically stable solution
Algorithm:
1) Take π β₯ 4 point matches (π₯, π₯β)
2) Compute T, and condition points: π₯ = ππ₯; π₯β = πβπ₯β
3) Assemble A with Ah = 0
4) compute π
β= ππππππ
βπ΄π subject to π = π, use SVD to do this.
4) Get H of unconditioned points: π
β²β1π»π (Note: π
β²π₯
β²= π»ππ₯)
Motivation for next lecture
Question 1: If a match is completly wrong then is a bad idea
Question 2: If a match is slighly wrong then might not be perfect.
Better might be a geometric error:
ππππππ
βπ΄π ππππππ
βπ΄π
ππππππ
βπ―π₯ β π₯β²
Can we get πΎβπ and π from π» ?
β’ Assume we have π» = πΎ 1 π πΎ 0 β1 of a rotating camera, can we get out πΎ 1 , π , πΎ 0 ?
β’ π» has 8 DoF
β’ πΎ 1 , π , πΎ 0 have together 13 DoF
β’ Not directly possible, only with assumptions on K.
(No application needs such a decomposition)
β’ For other transfromations such decompositions are possible
What can we do with π» ?
β’ Panoramic stitching with rotating camera (exercise later)
Warp images into a canonical view: π₯β² = π»π₯
What can we do with π» ?
What can we do with π» ?
β’ Plane-based augmented realty
Homography π» : Summary
β’ Derive geometrically π»
β’ Calibration: Take measurements (points) to compute π»
β’ Minimum of 4 points. Solution: right null space of π΄β = 0
β’ Many points. Use SVD to solve π
β= ππππππ
βπ΄π
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from π»?
-> hard. Not discussed much
β’ What can we do with π» ?
-> augmented reality on planes, panoramic stitching
Topic 2: Camera Matrix P
β’ Derive geometrically π
β’ Calibration: Take measurements (points) to compute π
β’ How do we do that with a minimal number of points?
β’ How do we do that with many points?
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from π?
β’ What can we do with π?
Geometric Derivation: Camera Matrix (Reminder)
β’ Camera matrix P has 11 DoF
β’ Intrinsic parameters
β’ Principal point coordinates (π π₯ , π π¦ )
β’ Focal length π
β’ Pixel magnification factors π
β’ Skew (non-rectangular pixels) π
β’ Extrinsic parameters
β’ Rotation πΉ (3DoF) and translation π (3DoF) relative to world coordinate system
π = π² πΉ (π°
πΓπ| β πͺ) πΏ ~
~
π² =
π π π
π₯0 ππ π
π¦0 0 1
π = π· πΏ
How can we compute/calibrate π ?
π = π² πΉ (π°
πΓπ| β πͺ) πΏ π = π· πΏ
Important move in all directions: π₯, π¦, π§
Calibration pattern
How can we compute/calibrate π ?
β’ We have ππ₯β² = ππ
β’ π has 11 DoF
β’ We get for each point pair (π₯β², π) 3 equations, but only 2 linear independent once, by taking ration (to get rid of π)
β’ We need a minimum of 6 Points to get 12 equations
Algorithm (DLT - Direct Linear Transform):
1) Take π β₯ 6 points.
2) Condition points π, π₯β² using π, πβ²
3) Assemble A with π΄π = 0 (π΄ ππ π Γ 12 and π is vectorized π) 4) compute π
β= ππππππ
ππ΄π subject to π = 1
use SVD to do this.
5) Get out unconditioned π = π
β²β1ππ (note πβπ₯β = π ππ)
Note: a version with minimal number of points (6) is same as with many points
Half-way slide
3 minutes break. Stand Up. Please ask me Questions.
An alternative: Lagrange Multiplier
Maximize π π₯, π¦ subject to π π₯, π¦ = π
Lagrange function: πΏ π₯, π¦, π = π π₯, π¦ + π (π π₯, π¦ β π) An optimal solution is obtained for:
ππΏ(π₯,π¦,π)
ππ₯
= 0 ;
ππΏ(π₯,π¦,π)ππ¦= 0 ;
ππΏ(π₯,π¦,π)ππ= 0 (these are 3 constraints and 3 unknowns)
Note:
ππΏ(π₯,π¦,π)ππ= π π₯, π¦ β π = 0 (the original constraint)
An alternative: Lagrange Multiplier
β’ Why does
ππΏ(π₯,π¦,π)ππ₯= 0 ;
ππΏ(π₯,π¦,π)ππ¦= 0 give an optimal solution for π
β’ Lagrange function: πΏ π₯, π¦, π = π π₯, π¦ + π (π π₯, π¦ β π)
β’ We have:
ππΏ(π₯,π¦,π)
ππ₯
=
ππ(π₯,π¦)ππ₯+ π
ππ(π₯,π¦)ππ₯
= 0
ππΏ(π₯,π¦,π)
ππ¦
=
ππ(π₯,π¦)ππ¦+ π
ππ(π₯,π¦)ππ¦= 0
β’ This means that gradients are aligned (
ππ(π₯,π¦)ππ₯,
ππ(π₯,π¦)ππ¦
) = - π (
ππ(π₯,π¦)ππ₯,
ππ(π₯,π¦)ππ¦
)
Gradient π Gradient π
(blackboard)
Lagrange Multiplier: Example
This gives:
4π12+
4π12-1 = 0; hence: π = +/β
12Maximize π π₯, π¦ = π₯ + π¦ subject to x
2+ y
2= 1
Lagrange function: πΏ π₯, π¦, π = π₯ + π¦ + π (π₯
2+ π¦
2β 1)
ππΏ(π₯,π¦,π)
ππ₯
= 1 + 2ππ₯ = 0 (gives: π₯ =
β12π)
ππΏ(π₯,π¦,π)
ππ¦
= 1 + 2ππ¦ = 0 (gives: y =
β12π)
ππΏ(π₯,π¦,π)
ππ
= π₯
2+ π¦
2β 1 = 0
Two Solutions:
β 22,
β 22,
22,
22We require:
How can we compute/calibrate π ?
β’ Goal: compute π
β= ππππππ
ππ΄π subject to π = 1
β’ Let us rewrite π = 1 as 1 β π
ππ = 0
β’ We have to solve the following problem:
π
ππ
π
ππ΄
ππ΄π + π 1 β π
ππ = 0 (note: π΄π = π
ππ΄
ππ΄π)
β’ This gives after some transformation: π΄
ππ΄π = ππ
β’ The solutions for π are the eigenvectors of π΄
ππ΄ and π the corresponding eigenvalues
β’ The least squared error is then:
ππππππ
ππ΄π = ππππππ
ππ
ππ΄
ππ΄π = ππππππ
ππ
πππ
note π΄ππ΄π = ππ
β’ Assume π is known, can we get out πΎ, π , πΆ ?
β’ P has 11 DoF
β’ πΎ, π , πΆ have together 5+3+3=11 DoF -> possible
β’ How to do it:
1) The camera center πΆ is the right nullspace of P ππΆ = πΎ π (πΆ β πΆ) = 0
2) π = [πΎπ | β πΎπ πΆ] ; π΄ = πΎπ
can be done with unique RQ decomposition, where R is upper- triangular matrix and Q a rotation matrix (see HZ page 579)
How can we get K,R,C from P
π = π² πΉ (π°
πΓπ| β πͺ) πΏ ~ π = π· πΏ
~
~
~
~
~
~
~
What can we do with π ?
β’ Many things can be done with an externally and internally calibrated camera
β’ Robot navigation, augmented reality, photogrammetry β¦
camera
Manipulator
Camera Matrix π : Summary
β’ Derive geometrically π
β’ Calibration: Take measurements (points) to compute π
β’ 6 or more points. Use SVD to solve π
β= ππππππ
βπ΄π
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from π»?
-> yes, use SVD and RQ decomposition
β’ What can we do with π ?
-> very many things (robotic, photogrammetry, augmented reality, β¦)
π = π² πΉ (π°
πΓπ| β πͺ) πΏ ~
π = π· πΏ
Topic 3: Fundamental/Essential Matrix πΉ/πΈ
β’ Derive geometrically πΉ/πΈ
β’ Calibration: Take measurements (points) to compute πΉ/πΈ
β’ How do we do that with a minimal number of points?
β’ How do we do that with many points?
β’ Can we derive the intrinsic (πΎ) an extrinsic (π , π) parameters from πΉ/πΈ?
β’ What can we do with πΉ/πΈ?
Reminder from Lecture 4: The 3D case
Illustration of the general 3D case
Appearance based matching:
Geometry based matching:
1) Assume sensible camera model. We will see that: Given 7 matching
3D points defines how other 3D points match.
3D Geometry
Non-moving scene
πβ
Rigidly (6D) -moving scene
Both cases are equivalent for the following derivations
Epipolar Geometry
Epipolar Geometry
Epipolar Geometry
Epipolar Geometry
Epipolar Geometry
Epipolar plane: Plane through both camera centers and world point.
Epipolar Geometry
Epipolar Geometry
β’ Epipolar lines:
β’ Intersect at the epipoles
β’ In general not parallel
Example: Converging Cameras
Example: Motion Parallel to Camera
β’ We will use this idea when it comes to stereo matching (in 2 lectures)
Example: Forward Motion
β’ Epipoles have same coordinate in both images
β’ Points move along lines radiating from epipole
The maths behind it: Fundamental/Essential Matrix
The 3 vectors are in same plane (co-planar):
1) π = πΆ
1β πΆ
02) π β πΆ
03) π β πΆ
1Set camera matrix: π₯
0= πΎ
0πΌ 0 π and π₯
1= πΎ
1π
β1πΌ βπΆ
1π The three rays are:
1) T 2) πΎ
0β1π₯
03) π πΎ
1β1π₯
1+ πΆ
1β πΆ
1= π πΎ
1β1π₯
1We know that:
πΎ
0β1π₯
0 ππ
Γπ (πΎ
1β1π₯
1) = 0 which gives: π₯
0ππΎ
0βππ
Γπ (πΎ
1β1π₯
1) = 0
~ ~ ~
~ ~
~ ~
~
~
~ ~
~ ~
The maths behind it: Fundamental/Essential Matrix
β’ In an un-calibrated setting (πΎβπ not known):
π₯ 0 π πΎ 0 βπ π Γ π (πΎ 1 β1 π₯ 1 ) = 0
β’ In short: π₯ 0 π πΉπ₯ 1 = 0 where F is called the Fundamental Matrix
(discovered by Faugeras and Luong 1992, Hartley 1992)
β’ In an calibrated setting ( πΎ βs are known):
we use rays: π₯ π = πΎ π β1 π₯ π
then we get: π₯ 0 π π Γ π π₯ 1 = 0
In short: π₯ 0 π πΈπ₯ 1 = 0 where E is called the Essential Matrix
(discovered by Longuet-Higgins 1981)
~
~
Fundamental Matrix: Properties
β’ We have π₯ 0 π πΉπ₯ 1 = 0 where F is called the Fundamental Matrix
β’ It is det πΉ = 0. Hence F has 7 DoF Proof: πΉ = πΎ 0 βπ π Γ π πΎ 1 β1
πΉ has Rank 2 since π Γ has Rank 2
~
Check: det( π₯
Γ) = π₯
3π₯
30 β π₯
1π₯
2+ π₯
2π₯
1π₯
3+ π₯
20 = 0
π
Γ=
0 βπ₯
3π₯
2π₯
30 βπ₯
1βπ₯
2π₯
10
~
Fundamental Matrix: Properties
β’ For any two matching points (i.e. have the same 3D point) we have: π₯ 0 π πΉπ₯ 1 = 0
β’ Compute epipolar line in camera 1 of a point π₯ 0 : π 1 π = π₯ 0 π πΉ (since π₯ 0 π πΉπ₯ 1 = π 1 π π₯ 1 = 0)
β’ Compute epipolar line in camera 1 of a point π₯ 0 :
π 0 = πΉπ₯ 1 (since π₯ 0 π πΉπ₯ 1 = π₯ 0 π π 0 = 0)
π
~
~
Fundamental Matrix: Properties
Camera 0
Camera 1