Camera Geometry II - Princeton University

87
Camera Geometry II COS 429 Princeton University

Transcript of Camera Geometry II - Princeton University

Page 1: Camera Geometry II - Princeton University

Camera Geometry II

COS 429

Princeton University

Page 2: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 3: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 4: Camera Geometry II - Princeton University

Review: Camera projection matrix

111 3333231

2232221

1131211

Z

Y

X

trrr

trrr

trrr

y

x

yy

xx

PXx

intrinsic

parameters

extrinsic

parameters

world

coordinate

system

camera

coordinate

system

Page 5: Camera Geometry II - Princeton University

Review: Camera parameters

• Intrinsic parameters

• Image center (px,py)

• Focal length (f)

• Pixel magnification (mx,my)

• Skew (non-rectangular pixels)

• Radial distortion

111

yy

xx

y

x

y

x

pf

pf

m

m

K

tRKP

Page 6: Camera Geometry II - Princeton University

Review: Camera parameters

• Intrinsic parameters

• Principal point coordinates

• Focal length

• Pixel magnification

• Skew (non-rectangular pixels)

• Radial distortion

• Extrinsic parameters

• Rotation (R) and translation (t) relative to

world coordinate system

tRKP

Page 7: Camera Geometry II - Princeton University

Review: Camera calibration

1****

****

****

1Z

Y

X

y

x

XtRKx

Source: D. Hoiem

Page 8: Camera Geometry II - Princeton University

Review: Camera calibration

• Given n points with known 3D coordinates Xi

and known image projections xi, estimate the

camera parameters

P

Xi

xi

Page 9: Camera Geometry II - Princeton University

Camera calibration

• What if don’t know correspondences?

• Can you determine the camera

intrinsic parameters (focal length, center) or

extrinsic parameters (rotation, translation)?

Page 10: Camera Geometry II - Princeton University

Camera calibration

• Let’s see what we can get from vanishing points

Vanishing point

Vanishing line

Vanishing point

Vertical vanishing point

(at infinity)

Slide from Efros, Photo from Criminisi

Page 11: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 12: Camera Geometry II - Princeton University

Review: Vanishing Points

v1 v2 l

– Any set of parallel lines

on a plane define a

vanishing point

– The union of all of

these vanishing points

is the horizon line

• also called vanishing line

– Different planes (can)

define different

vanishing lines

Noah Snavely

Page 13: Camera Geometry II - Princeton University

Review: Vanishing points

image plane

line in the scene

vanishing point v

• All lines having the same direction share the same

vanishing point

camera

center

Page 14: Camera Geometry II - Princeton University

Computing Vanishing Points

How can we find lines in an image?

Page 15: Camera Geometry II - Princeton University

Computing Vanishing Points

Edge detection

Papusha & Ho

Edges

Page 16: Camera Geometry II - Princeton University

Computing Vanishing Points

Edge detection + Hough transform

Papusha & Ho

Strong Lines Hough Transform

Page 17: Camera Geometry II - Princeton University

q1

Computing Vanishing Points

For a set of parallel lines, how can we find

where they intersect?

v

p1

p2

q2

Page 18: Camera Geometry II - Princeton University

q1

Computing Vanishing Points

Intersect p1q1 with p2q2

v

p1

p2

q2

Page 19: Camera Geometry II - Princeton University

q1

Computing Vanishing Points

Intersect p1q1 with p2q2

v

p1

p2

q2

Page 20: Camera Geometry II - Princeton University

q1

Computing Vanishing Points

Intersect p1q1 with p2q2

v

p1

p2

q2

Page 21: Camera Geometry II - Princeton University

q1

Computing Vanishing Points

Intersect p1q1 with p2q2

v

p1

p2

q2

Least squares version

• Better to use more than two lines and compute

the “closest” point of intersection

Page 22: Camera Geometry II - Princeton University

Computing Vanishing Points

Alternative: vanishing points can be extracted

directly from Hough transform (fit sine curves)

Papusha & Ho

Strong Lines Hough Transform

Page 23: Camera Geometry II - Princeton University

Computing Vanishing Points

Vanishing points can be extracted directly from

Hough transform (fit sine curves)

Papusha & Ho

Hough Transform

Strong Lines

Page 24: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 25: Camera Geometry II - Princeton University

Calibration from vanishing points

• What camera parameters can we calibrate using

three orthogonal vanishing directions (points)?

v1

v3 .

v2

Page 26: Camera Geometry II - Princeton University

Calibration from vanishing points

• Let us align the world coordinate system with three

orthogonal vanishing directions in the scene:

• Each pair of vanishing points gives us a constraint

on the focal length and principal point

1

0

0

,

0

1

0

,

0

0

1

321 eee i

i

i KRee

tRKv

0|

0,1

j

T

ii

T

i eevKRe

011

j

TT

ij

TTT

i vKKvvKRRKv

Page 27: Camera Geometry II - Princeton University

Intrinsic calibration from vanishing points

Can solve for focal length, image center Cannot recover focal

length, image center is the

finite vanishing point

Page 28: Camera Geometry II - Princeton University

Rotation from vanishing points

Thus,

Get λ by using the constraint ||ri||2=1.

i

i

i KRee

tRKv

0|

132111

1

0

0

1

][ rrrrRevK

.1

ii rvK

Page 29: Camera Geometry II - Princeton University

Calibration from vanishing points: Summary

• Solve for K (focal length, principal point) using three

orthogonal vanishing points

• Get rotation directly from vanishing points once

K is known

• Advantages

• No need for calibration chart

(2D-3D correspondences)

• Could be completely automatic

• Disadvantages

• Only applies to certain kinds of scenes

• Inaccuracies in computation of vanishing points

• Problems due to infinite vanishing points

Page 30: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 31: Camera Geometry II - Princeton University

How Tall is the Man in this Image?

Svetlana Lazebnik

Page 32: Camera Geometry II - Princeton University

How Tall is the Man in this Image?

10 meters

Svetlana Lazebnik

Page 33: Camera Geometry II - Princeton University

How Tall is the Man in this Image?

10 meters

Svetlana Lazebnik

Page 34: Camera Geometry II - Princeton University

O

How Tall is the Man in this Image?

ground plane

Goal: compute Z

Z

Problem: depends on camera angle and distance

10 meters

Svetlana Lazebnik

Page 35: Camera Geometry II - Princeton University

The cross-ratio

• A projective invariant: quantity that does not change

under projective transformations (including perspective

projection)

• The cross-ratio of four points:

P1

P2

P3 P4

1423

2413

PPPP

PPPP

Svetlana Lazebnik

Page 36: Camera Geometry II - Princeton University

vZ

r

t

b

tvbr

rvbt

Z

Z

image cross ratio

Measuring height

B (bottom of object)

T (top of object)

R (reference point)

ground plane

H C

TBR

RBT

scene cross ratio

R

H

R

H

R

Svetlana Lazebnik

Page 37: Camera Geometry II - Princeton University

How Tall is the Man in this Image?

10 meters

Svetlana Lazebnik

Page 38: Camera Geometry II - Princeton University

R H

vz

r

b

t

R

H

Z

Z

tvbr

rvbt

image cross ratio

H

b0

t0

v vx vy

vanishing line (horizon)

Svetlana Lazebnik

Page 39: Camera Geometry II - Princeton University

2D lines in homogeneous coordinates

• Line equation: ax + by + c = 0

• Line passing through two points:

• Intersection of two lines:

1

, where0 y

x

c

b

aT

xlxl

21 xxl

21 llx

Svetlana Lazebnik

Page 40: Camera Geometry II - Princeton University

R H

vz

r

b

t

R

H

Z

Z

tvbr

rvbt

image cross ratio

H

b0

t0

v vx vy

vanishing line (horizon)

Svetlana Lazebnik

Page 41: Camera Geometry II - Princeton University

How Long is this Line Segment?

Can we measure distances between

two points on same plane?

Svetlana Lazebnik

Page 42: Camera Geometry II - Princeton University

How Long is this Line Segment?

What if we know distances between some

pairs of points on the same plane?

Svetlana Lazebnik

Page 43: Camera Geometry II - Princeton University

Measurements on planes

1 2 3 4

1

2

3

4

p′

Approach: unwarp then measure

p

What kind of warp is this?

Svetlana Lazebnik

Page 44: Camera Geometry II - Princeton University

Measurements on planes

1 2 3 4

1

2

3

4

p′

Approach: unwarp then measure

p

Homography!

Svetlana Lazebnik

Page 45: Camera Geometry II - Princeton University

Application: Image rectification

Piero della Francesca, Flagellation, ca. 1455

Svetlana Lazebnik

Page 46: Camera Geometry II - Princeton University

Application: Image editing

Inserting synthetic objects into images:

http://vimeo.com/28962540

K. Karsch and V. Hedau and D. Forsyth and D. Hoiem, “Rendering Synthetic Objects into

Legacy Photographs,” SIGGRAPH Asia 2011 Svetlana Lazebnik

Page 47: Camera Geometry II - Princeton University

Application: Object recognition

D. Hoiem, A.A. Efros, and M. Hebert, "Putting Objects in Perspective", CVPR 2006

Svetlana Lazebnik

Page 48: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 49: Camera Geometry II - Princeton University

• Given p in left image, where can corresponding

point p’ be?

Correspondence constraints?

Kristen Grauman

Page 50: Camera Geometry II - Princeton University

Kristen Grauman

Correspondence constraints?

Page 51: Camera Geometry II - Princeton University

Geometry of two views constrains where the corresponding pixel

for some image point in the first view must occur in the second

view.

It must be on the line carved out by a plane

connecting the world point and optical centers.

Epipolar constraint

Kristen Grauman

Page 52: Camera Geometry II - Princeton University

• Epipolar Plane

Epipole

Epipolar Line

Baseline

Epipolar geometry

Epipole

http://www.ai.sri.com/~luong/research/Meta3DViewer/EpipolarGeo.html

Kristen Grauman

Page 53: Camera Geometry II - Princeton University

Baseline: line joining the camera centers

Epipole: point of intersection of baseline with image plane

Epipolar plane: plane containing baseline and world point

Epipolar line: intersection of epipolar plane with the image

plane

All epipolar lines intersect at the epipole

An epipolar plane intersects the left and right image planes in

epipolar lines

Epipolar geometry: terms

Why is the epipolar constraint useful? Kristen Grauman

Page 54: Camera Geometry II - Princeton University

Epipolar constraint

This is useful because it reduces the correspondence problem to

a 1D search along an epipolar line.

Image from Andrew Zisserman

Page 55: Camera Geometry II - Princeton University

Example

Kristen Grauman

Page 56: Camera Geometry II - Princeton University

What do the epipolar lines look like?

Ol Or

Ol Or

1.

2.

Kristen Grauman

Page 57: Camera Geometry II - Princeton University

Epipolar lines: converging cameras

Figure from Hartley & Zisserman

Page 58: Camera Geometry II - Princeton University

Figure from Hartley & Zisserman

Where are

the epipoles?

Epipolar lines: parallel cameras

Page 59: Camera Geometry II - Princeton University

So far, we have the explanation in terms of

geometry.

Now, how to express the epipolar constraints

algebraically?

Kristen Grauman

Epipolar lines

Page 60: Camera Geometry II - Princeton University

Stereo geometry

Main idea

Kristen Grauman

Page 61: Camera Geometry II - Princeton University

If the stereo rig is calibrated, we know :

how to rotate and translate camera reference frame 1 to get to

camera reference frame 2. Rotation: 3 x 3 matrix R; translation: 3 vector T.

Kristen Grauman

Stereo geometry

Page 62: Camera Geometry II - Princeton University

If the stereo rig is calibrated, we know :

how to rotate and translate camera reference frame 1 to get to

camera reference frame 2.

TRXX cc'Kristen Grauman

Stereo geometry

Page 63: Camera Geometry II - Princeton University

An aside: cross product

Vector cross product takes two vectors and

returns a third vector that’s perpendicular to

both inputs.

So here, c is perpendicular to both a and b,

which means the dot product = 0.

Kristen Grauman

Page 64: Camera Geometry II - Princeton University

From geometry to algebra

TRXX'

TTRXTXT

RXT

RXTXXTX

0Normal to the plane

Kristen Grauman

Page 65: Camera Geometry II - Princeton University

Another aside: Matrix form of cross product

Can be expressed as a matrix multiplication.

c

b

b

b

aa

aa

aa

ba

3

2

1

12

13

23

0

0

0

0

0

0

12

13

23

aa

aa

aa

ax

Kristen Grauman

Page 66: Camera Geometry II - Princeton University

From geometry to algebra

TRXX'

TTRXTXT

RXT

RXTXXTX

0Normal to the plane

Kristen Grauman

Page 67: Camera Geometry II - Princeton University

Essential matrix

0 RXTX

0][T RXX x

E is called the essential matrix, and it relates corresponding

image points between both cameras, given the rotation and

translation.

If we observe a point in one image, its position in other image is

constrained to lie on line defined by above.

Note: these points are in camera coordinate systems.

Let RE ][T x

0 EXXT

Kristen Grauman

Page 68: Camera Geometry II - Princeton University

Fundamental matrix

Relates pixel coordinates in the two views

More general form than essential matrix: we

remove need to know intrinsic parameters

If we estimate fundamental matrix from

correspondences in pixel coordinates, can

reconstruct epipolar geometry without intrinsic or

extrinsic parameters.

0,,

leftimrightim Fpp

Page 69: Camera Geometry II - Princeton University

0,,

leftcrightc Epp From before, the essential

matrix E.

0,

1

,

1

leftimint,leftrightimint,right pMEpM

0,

1

,

leftimint,leftint,rightrightim pEMMp

0,,

leftimrightim Fpp

“Fundamental matrix” F

Fundamental Matrix

Page 70: Camera Geometry II - Princeton University

Properties of the Fundamental Matrix

• is the epipolar line associated with

• is the epipolar line associated with

• and

• is rank 2

T

e1 e2

q p

Fp FTq

Page 71: Camera Geometry II - Princeton University

If we don’t know K1, K2, R, or t, can we estimate F

for two images?

Yes, given enough correspondences

Estimating the Fundamental Matrix

Page 72: Camera Geometry II - Princeton University

Estimating F – 8-point algorithm

The fundamental matrix F is defined by

0

Fxx'for any pair of matches x and x’ in two images.

• Let x=(u,v,1)T and x’=(u’,v’,1)T,

333231

232221

131211

fff

fff

fff

F

each match gives a linear equation

0'''''' 333231232221131211 fvfuffvfvvfuvfufvufuu

Page 73: Camera Geometry II - Princeton University

0

1´´´´´´

1´´´´´´

1´´´´´´

33

32

31

23

22

21

13

12

11

222222222222

111111111111

f

f

f

f

f

f

f

f

f

vuvvvvuuuvuu

vuvvvvuuuvuu

vuvvvvuuuvuu

nnnnnnnnnnnn

In reality, instead of solving , we seek f to

minimize , least eigenvector of . 0Af

Af AA

Estimating F – 8-point algorithm

Page 74: Camera Geometry II - Princeton University

F should have rank 2

To enforce that F is of rank 2, F is replaced by F’

that minimizes subject to the rank

constraint.

'FF

• This is achieved by SVD. Let , where

, let

then is the solution.

VUF Σ

3

2

1

00

00

00

Σ

000

00

00

Σ' 2

1

VUF Σ''

Estimating F – 8-point algorithm

Page 75: Camera Geometry II - Princeton University

Pros: it is linear, easy to implement and fast

Cons: susceptible to noise

Estimating F – 8-point algorithm

Page 76: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 77: Camera Geometry II - Princeton University

Stereo Correspondence

Goal:

• Find correspondences (pairs of points (u’,v’) ↔ (u,v)).

1) Find interest points in image

2) Compute correspondences

3) Compute epipolar geometry

4) Refine

Example from Andrew Zisserman

Page 78: Camera Geometry II - Princeton University

1) Find interest points

Stereo Correspondence

Page 79: Camera Geometry II - Princeton University

2) Match points within proximity to get putative matches

Stereo Correspondence

Page 80: Camera Geometry II - Princeton University

3) Compute epipolar geometry -- robustly with RANSAC

Select random sample of

putative correspondences

Compute F using them

- determines epipolar constraint

Evaluate amount of support

- inliers within threshold distance of

epipolar line

Choose F with most support

(inliers)

Stereo Correspondence

Page 81: Camera Geometry II - Princeton University

Using window

search to get

putative matches:

noisy, but enough

to compute F

using RANSAC

Pruned

matches: those

consistent with

epipolar

geometry

Page 82: Camera Geometry II - Princeton University

Outline

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited

Page 83: Camera Geometry II - Princeton University

Structure from Motion

1. Detect features using SIFT

2. Match features between pairs of images

3. Refine matching using RANSAC to find

correspondences between each pair

4. Massive bundle adjustment

Noah Snavely

Page 84: Camera Geometry II - Princeton University

Structure from Motion

1. Detect features using SIFT

2. Match features between pairs of images

3. Refine matching using RANSAC to find

correspondences between each pair

4. Massive bundle adjustment

Noah Snavely

Use fundamental matrix to

detect inliers during RANSAC!

Page 85: Camera Geometry II - Princeton University

Structure from Motion Results

Noah Snavely

Page 86: Camera Geometry II - Princeton University

Structure from Motion Results

Noah Snavely

Page 87: Camera Geometry II - Princeton University

Recap

Projective geometry

Vanishing points

Application: camera calibration

Application: single-view metrology

Epipolar geometry

Application: stereo correspondence

Application: structure from motion revisited