2D projective transformations (homographies) · PDF file2D projective transformations...
Transcript of 2D projective transformations (homographies) · PDF file2D projective transformations...
2
Introduction
• Previous lectures: – From world to image– Homogeneous coordinates– Intrinsic and extrinsic camera parameters– Camera calibration, P‐matrix estimation
• Today: (slides partly based on Marc Pollefeys)– Homographies– Homography estimation– Applications: panorama stitching, rotating camera, pose estimation
from planar surfaces
3
Reminder: homogeneous coordinates
• Allow to manipulate n‐dim vectors in a n+1‐dim space • For n=2: R2 P2
• Infinite points are represented with w=0
3 entries, but only 2 degrees of freedom
(DOF)
Where is this useful in computer vision?
Converting to homogeneousimage coordinates
Converting from homogeneousimage coordinates
0,,0,0
,0
yx
4
Reminder: homogeneous coordinates
• A vector in P is just a representative of an equivalence class of vectors• Everything is up‐to‐scale!
Unknown scale factor!
“proportional to”
0,1,,1,, wyxwyxp TT
5
Follow‐up: intrinsic parameters
Distorted coordinats
6
Follow‐up: extrinsic parameters and P‐matrix
P does not include lens distortion!This makes it a
nonlinear function.
How do cw and wc relate?
“proportional to”
7
Follow‐up: extrinsic parameters and P‐matrixHow do mw and mc relate?
or
wc???
P does not include lens distortion!This makes it a
nonlinear function.
In matrix form:
8
2D homography (projective transformation)
A 2D homography is an invertible mapping h from P2 to itself such that three points x1,x2,x3 lie on the same line if and only if h(x1),h(x2),h(x3) do.
Definition:
A mapping h: P2P2 is a homography if and only if there exist a non‐singular 3x3 matrix H such that for any point in P2
represented by a vector x it is true that h(x)=Hx
Theorem:
Definition: Homography
3
2
1
333231
232221
131211
3
2
1
'''
xxx
hhhhhhhhh
xxx
x=x' Hor
8DOF
Homography=projective transformation=projectivity=collineation
Line preserving
9
General homography
• Note: homographies are not restricted to P2
• General definition: A homography is a non‐singular, line preserving, projective mapping h: Pn Pn. It is represented by a square (n + 1)‐dim matrix with (n + 1)2‐1 DOF
• Now back to the 2D case…• Mapping between planes
10
1YX
H
Homographies in computer vision
Rotating/translating camera, planar world
What happens to the P‐matrix, if Z is assumed zero?
PXxyx T 1,,
H
H
H
11
1
321 ZYX
trrrK
Homographies in computer vision
Rotating camera, arbitrary world
What happens to the P‐matrix, if t is assumed zero?
''1 HxxKRK
PXxyx T 1,,
12
Transformation hierarchy: isometries
(iso=same, metric=measure)
1100cossinsincos
1''
yx
tt
yx
y
x
1
11
orientation preserving:orientation reversing:
x0
xx'
1t
T
RHE IRR T
special cases: pure rotation, pure translation
3DOF (1 rotation, 2 translation)
Invariants: length, angle, area
13
Transformation hierarchy: similarities
(isometry + scale)
1100cossinsincos
1''
yx
tsstss
yx
y
x
x0
xx'
1t
T
RH
sS IRR T
also know as equi‐form (shape preserving)metric structure = structure up to similarity (in literature)
4DOF (1 scale, 1 rotation, 2 translation)
Invariants: ratios of length, angle, ratios of areas, parallel lines
14
11001''
2221
1211
yx
taataa
yx
y
x
x0
xx'
1t
T
AH A
non‐isotropic scaling! (2DOF: scale ratio and orientation)
6DOF (2 scale, 2 rotation, 2 translation)
Invariants: parallel lines, ratios of parallel lengths,ratios of areas
DRRRA
2
1
00
D
Transformation hierarchy: affine transformations
15
xv
xx'
vP T
tAH
Acts non‐homogeneous over the plane
8DOF (2 scale, 2 rotation, 2 translation, 2 line at infinity)
Invariants: cross‐ratio of four points on a line(ratio of ratio)
T21,v vv
333231
232221
131211
vvt
hhhhhhhhh
TP
A
H
Allows to observe vanishing points,
horizon
Transformation hierarchy: homographies
Changes homogeneous coordinate!
16
1002221
1211
y
x
taataa
1002221
1211
y
x
tsrsrtsrsr
333231
232221
131211
hhhhhhhhh
1002221
1211
y
x
trrtrr
Projective8dof
Affine6dof
Similarity4dof
Euclidean3dof
2D transformation hierarchy
A square transforms to:
17
• Before: – What is a homography and how does it act on vectors/points
• Now: – How to estimate a homography from point correspondences– Same procedure as for P‐matrix
18
Homography estimation
• Estimate homography from point correspondences between:– two images– model plane and image
• Assumption: planar motion!
H
H
H
19
Homography estimation
• Homography mapping from image to image (holds under planar camera motion as mentioned before):
11 333231
232221
131211
yx
hhhhhhhhh
yx
Hxx '
20
Homography estimation
• Equation for one point correspondence i:
iT
T
T
ii xhhh
xHx
3
2
1
11 333231
232221
131211
i
i
i
i
yx
hhhhhhhhh
yx
0 ii xHx
3 equations, only 2 linearly independent, drop third row
9 entries, 8 degrees of freedom(scale is arbitrary)
ith row of H
iiii
iiii
iiii
ii
yxxwwy
xhxhxhxhxhxh
Hxx12
31
23
TT
TT
TT
0hhh
0xxx0x
xx0
3
2
1
TTT
TTT
TTT
iiii
iiii
iiii
xyxw
yw
Homogeneous coordinate, might be 1
21
Direct linear transform
• H has 8 DOF (9 parameters, but scale is arbitrary)• One correspondence gives two linearly independent equations• Four matches needed for a minimal solution (null space of 8x9 matrix)• More points: search for “best” according to some cost function
0h
A
AA
n
2
1
0Ah
22
Direct linear transform
• No exact solution because of inexact measurements due to noise• With n correspondences: size A is 2nx9, rank most likely not 8
• Find approximate solution– Additional constraint needed to avoid 0, e.g.– not possible, so minimize
0Ah 0h
A
AA
n
2
1
1h Ah0Ah
23
DLT algorithm
ObjectiveGiven n≥4 2D to 2D point correspondences {xi↔xi’}, determine the 2D homography matrix H such that xi’=Hxi
Algorithm(i) For each correspondence xi ↔xi’ compute Ai. Usually only
two first rows needed.
(ii) Assemble n 2x9 matrices Ai into a single 2nx9 matrix A(iii) Obtain SVD of A. Solution for h is last column of V,
=singular value of A=eigen vector to the smallest eigen value of ATA
(iv) Determine H from h
24
Inhomogeneous solution
''
h~''000''''''''000
ii
ii
iiiiiiiiii
iiiiiiiiii
xwyw
xyxxwwwywxyyyxwwwywx
Since h can only be computed up to scale, impose constraint pick hj=1, e.g. h9=1, and solve for 8‐vector
Can be solved using linear least‐squares
However, if h9=0 this approach fails Also poor results if h9 close to zeroTherefore, not recommended
And what now?
What can we do when knowing the homography between two images
26
Application (1): panorama stitching
x‘ ~ Hx
x‘x
Panorama stitching:1. Undistort images2. Find point correspondences between images3. Compute homography H4. Resample:
1. Loop over image 12. Project into image 2 using H3. Bilinear interpolation in image 2
Image 1 Image 2
27
Application (2): camera pose estimation
• Assuming that K (intrinsic calibration matrix) is known, derive the 3D camera pose from H
• Enables augmentation of 3D virtual objects (augmented reality)– Set virtual camera to real camera– Render virtual scene– Compose with real image
• Enables localization/navigation• Recall the two cases of planar motion:
– purely rotating camera, arbitrary scene– Rotating and translating camera, planar scene
28
Camera pose estimation
• Purely rotating camera:
Movie
29
Camera pose estimation
• Planar scene (example marker tracker, applies to any planar scene):
H
30
–r1 and r2 are unit vectors find lambda–Use this to compute t–Rotation matrices are orthogonal find r3
Assume all points lie in one plane with Z=0:
Camera pose estimation
31
Problems
• Problem:– The vectors r1 and r2 might not yield the same lambda
• Solution:– Use the average value
• Problem:– The estimated rotation matrix might not be orthogonal
• Solution: orthogonalize R’– Obtain SVD R’=UWVT
– Set singular values to 1 R=UVT
32
Video‐inputPattern recognition
(point correspondences from 4 corners)
Homography 3D pose
Synthesis and overlay
Rendering of the virtual object
Example: marker tracker
33
Example: natural feature tracking
Life image with augmentations Virtual scene
34
References
• Homography estimation from planes:– Zhang: Flexible camera calibration by viewing a plane from unknown
orientations, ICCV, 1999.• Homography estimation from purely rotating camera
– Hartley: Self‐Calibration from Multiple Views with a Rotating Camera, ECCV, 1994
– Brown and Lowe: Recognizing Panoramas, ICCV, 2003.
Thank you!
Next lecture:Linear/nonlinear/robust estimation techniques