94
Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869: Advances in Computer Vision Antonio Torralba and Bill Freeman

Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Lecture11Geometry,CameraCalibration,andStereo.

6.819 / 6.869: Advances in Computer Vision

Antonio Torralba and Bill Freeman

Page 2: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

2dfrom3d;3dfrommultiple2dmeasurements

?

?

2d 3d

Page 3: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Perspective projection

image plane

(0,0,0)

Virtual image plane

f f

Page 4: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Perspective projection

(0,0,0)

f Z

Y

y ?

y = f Y/Z

Similar triangles: y / f = Y / Z

X,Y,Z( )⇒ f XZ, f YZ

⎝ ⎜

⎠ ⎟

Perspective projection:

Virtual image plane

Page 5: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

http://www.ider.herts.ac.uk/school/courseware/graphics/two_point_perspective.html

Vanishing points

Page 6: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Other projection models: Orthographic projection

),(),,( yxzyx →

Page 7: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Three camera projections

(1) Perspective:

(2) Weak perspective:

(3) Orthographic: ),(),,(

,),,(

,),,(

00

yxzyx

zfy

zfx

zyx

zfy

zfx

zyx

⎟⎟⎠

⎞⎜⎜⎝

⎛→

⎟⎠

⎞⎜⎝

⎛→

3-d point 2-d image position

Page 8: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Three camera projections

Perspective projection Parallel (orthographic) projection

Weak perspective?

Page 9: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Homogeneous coordinatesIs the perspective projection a linear transformation?

Trick: add one more coordinate:

Converting from homogeneous coordinates

homogeneous image coordinates

• no—division by z is nonlinear

homogeneous world coordinates

Slide by Steve Seitz

Page 10: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Perspective Projection• Projection is a matrix multiply using homogeneous coordinates:

This is known as perspective projection • The matrix is the projection matrix

Slide by Steve Seitz

1 0 0 00 1 0 00 0 1/ f 0

⎢ ⎢ ⎢

⎥ ⎥ ⎥

xyz1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

xyz / f

⎢ ⎢ ⎢

⎥ ⎥ ⎥

⇒ f xz, f y

z⎛

⎝ ⎜

⎠ ⎟

Page 11: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Perspective ProjectionHow does scaling the projection matrix change the transformation?

Slide by Steve Seitz

1 0 0 00 1 0 00 0 1/ f 0

⎢ ⎢ ⎢

⎥ ⎥ ⎥

xyz1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

xyz / f

⎢ ⎢ ⎢

⎥ ⎥ ⎥

⇒ f xz, f y

z⎛

⎝ ⎜

⎠ ⎟

f 0 0 00 f 0 00 0 1 0

⎢ ⎢ ⎢

⎥ ⎥ ⎥

xyz1

⎢ ⎢ ⎢ ⎢

⎥ ⎥ ⎥ ⎥

=

fxfyz

⎢ ⎢ ⎢

⎥ ⎥ ⎥

⇒ f xz, f y

z⎛

⎝ ⎜

⎠ ⎟

Page 12: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Orthographic ProjectionSpecial case of perspective projection

• Also called “parallel projection” • What’s the projection matrix?

Image World

Slide by Steve Seitz

?

Page 13: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Orthographic ProjectionSpecial case of perspective projection

• Distance from the COP to the PP is infinite

• Also called “parallel projection” • What’s the projection matrix?

Image World

Slide by Steve Seitz

Page 14: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

2D Transformations

Page 15: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

2D Transformations

tx

ty= +

Example: translation

Page 16: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

2D Transformations

tx

ty= +

1

=1 0 tx

0 1 ty.

Example: translation

Page 17: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

2D Transformations

tx

ty= +

1

=1 0 tx

0 1 ty.

=1 0 tx

0 1 ty

0 0 1

.

Example: translation written 3 ways: non-homog homog in, non-h out, homog in, homog out

Now we can chain transformations

Page 18: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Translation and rotation, written in each set of coordinates

Non-homogeneous coordinates

B ! p =ABR A! p +A

B! t

ABC =

− − −

− AB R −

− − −

|

AB ! t |

0 0 0 1

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

B ! p =ABC A! p

Homogeneous coordinates

where

from

to

Page 19: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibrationUse the camera to tell you things about the

world: – Relationship between coordinates in the world

and coordinates in the image: geometric camera calibration, see Szeliski, section 5.2, 5.3 for references

– (Relationship between intensities in the world and intensities in the image: photometric image formation, see Szeliski, sect. 2.2.)

Page 20: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibration

• Intrinsic parameters

• Extrinsic parameters

Image coordinates relative to camera !" Pixel coordinates

Camera frame 1 !" Camera frame 2

Page 21: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibration

• Intrinsic parameters • Extrinsic parameters

Page 22: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Intrinsic parameters: from idealized world coordinates to pixel values

Forsyth&Ponce

zy

fvzxfu

=

=Perspective projection

Page 23: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Intrinsic parameters

zy

vzx

u

α

α

=

=But “pixels” are in some arbitrary spatial units

Page 24: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Intrinsic parameters

zy

vzx

u

β

α

=

=Maybe pixels are not square

Page 25: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Intrinsic parameters

0

0

vzy

v

uzx

u

+=

+=

β

αThe origin of our camera pixel coordinates may be somewhere other than under the camera optical axis.

Page 26: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Intrinsic parameters

0

0

)sin(

)cot(

vzy

v

uzy

zx

u

+=

+−=

θ

β

θαα

May be skew between camera pixel axes (but usually this angle is 90 deg).

v

θu

vʹ uʹ

vuvuuvv

)cot()cos()sin(

θθ

θ

−=ʹ−=ʹ

Page 27: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

! p = K C! p

Intrinsic parameters, homogeneous coordinates

0

0

)sin(

)cot(

vzy

v

uzy

zx

u

+=

+−=

θ

β

θαα

uv1

⎜ ⎜ ⎜

⎟ ⎟ ⎟

=

α −α cot(θ) u00 β

sin(θ)v0

0 0 1

000

⎜ ⎜ ⎜

⎟ ⎟ ⎟

xyz1

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

Using homogenous coordinates, we can write this as:

or:

In camera-based coordsIn pixels

Page 28: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibration

• Intrinsic parameters • Extrinsic parameters

Page 29: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

World and camera coordinate systems

In the first lecture, we placed the world coordinates in the center of the scene.

Page 30: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Extrinsic parameters: translation and rotation of camera frame

C ! p =WCR W! p +W

C! t Non-homogeneous coordinates

Homogeneous coordinates

C ! p ⎛

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

=

− − −

− WC R −

− − −

|

WC ! t |

0 0 0 1

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

W ! p ⎛

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

Page 31: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Combining extrinsic and intrinsic calibration parameters, in homogeneous coordinates

Forsyth&Ponce

! p = K C! p Intrinsic

Extrinsic

C ! p ⎛

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

=

− − −

− WC R −

− − −

|

WC ! t |

0 0 0 1

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

W ! p ⎛

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

World coordinatesCamera coordinates

pixels

! p = K WC R W

C ! t ( ) W! p

! p = M W! p €

0 0 0 1

Page 32: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Other ways to write the same equation

uv1

⎜ ⎜ ⎜

⎟ ⎟ ⎟

=

. m1T . .

. m2T . .

. m3T . .

⎜ ⎜ ⎜

⎟ ⎟ ⎟

W pxW pyW pz1

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟

! p = M W! p

PmPmv

PmPmu

!!!!

⋅=

⋅=

3

2

3

1

pixel coordinates

world coordinates

Conversion back from homogeneous coordinates leads to:

Page 33: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Projection equation

• The projection matrix models the cumulative effect of all parameters • Useful to decompose into a series of operations

ΠXx =

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

=

⎥⎥⎥

⎢⎢⎢

=

1************

ZYX

ssysx

Π =

− fsx 0 x 'c0 − fsy y 'c0 0 1

⎢ ⎢ ⎢

⎥ ⎥ ⎥

1 0 0 00 1 0 00 0 1 0

⎢ ⎢ ⎢

⎥ ⎥ ⎥

R3x3 03x101x3 1

⎣ ⎢ ⎢

⎦ ⎥ ⎥

I3x3 T3x1

01x3 1

⎣ ⎢ ⎢

⎦ ⎥ ⎥

projectionintrinsics rotation translation

identity matrix

Summary camera parametersA camera is described by several parameters

• Translation T of the optical center from the origin of world coords • Rotation R of the image plane • focal length f, principle point (x’c, y’c), pixel size (sx, sy) • blue parameters are called “extrinsics,” red are “intrinsics”

• The definitions of these parameters are not completely standardized – especially intrinsics—varies from one book to another

Page 34: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

do we calculate the camera’s calibration matrix, or measure?

Page 35: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Calibration target

Find the position, ui and vi, in pixels, of each calibration object feature point.

Page 36: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibrationFrom before, we had these equations relating image positions, u,v, to points at 3-d positions P (in homogeneous coordinates):

So for each feature point, i, we have:

Page 37: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Camera calibrationStack all these measurements of i=1…n points

into a big matrix (cluttering vector arrows omitted from P and m):

Page 38: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Showing all the elements:

In vector form: Camera calibration

Page 39: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

We want to solve for the unit vector m (the stacked one) that minimizes

Q m = 0

The minimum eigenvector of the matrix QTQ gives us that (see Forsyth&Ponce, 3.1), because it is the unit vector x that minimizes xT QTQ x.

Camera calibration

Page 40: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Once you have the M matrix, can recover the intrinsic and extrinsic parameters.

Camera calibration

Page 41: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Vision systems

One cameraTwo cameras N cameras

Page 42: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereovision

~6cm ~50cm

Page 43: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Depth without objectsRandom dot stereograms (Bela Julesz)

Julesz, 1971

Page 44: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo photography and stereo viewers

Image courtesy of fisher-price.com

Take two pictures of the same subject from two slightly different viewpoints and display so that each eye sees only one of the images.

Slide credit: Kristen Grauman

Page 45: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Public Library, Stereoscopic Looking Room, Chicago, by Phillips, 1923

Slide credit: Kristen Grauman

Page 46: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Anaglyphpinholecamera

Page 47: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Autostereograms

Images from magiceye.com

Exploit disparity as depth cue using single image.

(Single image random dot stereogram, Single image stereogram)

Slide credit: Kristen Grauman

Page 48: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Myconundrumregardingstereodisplays

Real3dscenesoftenlooktomelikethin,flatlayers,stackedindepth.Whyisthat?

48

Page 49: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Estimatingdepthwithstereo

• Stereo:shapefromdisparitiesbetweentwoviews• We’llneedtoconsider:

– Infooncamerapose(“calibration”)– Imagepointcorrespondences

scene point

optical center

image plane

Slide credit: Kristen Grauman

Page 50: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Geometry for a simple stereo system

• Assume a simple setting: – Two identical cameras – parallel optical axes – known camera parameters (i.e., calibrated cameras).

Ol Or

Page 51: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

baseline

optical center (left)

optical center (right)

Focal length

World point

Depth of pimage point (left)

image point (right)

Slide credit: Kristen Grauman

Page 52: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

• Assume parallel optical axes, known camera parameters (i.e., calibrated cameras). We can triangulate via:

Similar triangles (pl, P, pr) and (Ol, P, Or):

Geometry for a simple stereo system

disparity

Slide credit: Kristen Grauman

Page 53: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Depth from disparity

image I(x,y) image I´(x´,y´)Disparity map D(x,y)

(x´,y´)=(x+D(x,y), y)

Slide credit: Kristen Grauman

Page 54: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

General case, with calibrated cameras • The two cameras need not have parallel optical axes.

Vs.

Page 55: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo correspondence constraints

O O’

pp’ ?

If we see a point in camera 1, are there any constraints on where wewill find it on camera 2?

Camera 1 Camera 2

Page 56: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

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.

Why is this useful?

Epipolar constraint

O O’

pp’ ?

Page 57: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Epipolar constraint

This is useful because it reduces the correspondence problem to a 1D search along an epipolar line.

Image from Andrew Zisserman Slide credit: Kristen Grauman

Page 58: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

• Epipolar Plane

Epipole

Epipolar Line

Baseline

Epipolar geometry

Epipole

http://www.ai.sri.com/~luong/research/Meta3DViewer/EpipolarGeo.html Slide credit: Kristen Grauman

• Epipolar plane: plane containing baseline and world point • Epipole: point of intersection of baseline with the image plane • Epipolar line: intersection of epipolar plane with the image plane • Baseline: line joining the camera centers

• All epipolar lines intersect at the epipole • An epipolar plane intersects the left and right image planes in epipolar lines

Epipolar Line

Page 59: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Example

Slide credit: Kristen Grauman

Page 60: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Figure from Hartley & Zisserman

Example: parallel cameras

Where are the epipoles?

Slide credit: Kristen Grauman

Page 61: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Example: converging cameras

Figure from Hartley & Zisserman Slide credit: Kristen Grauman

Page 62: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

• So far, we have the explanation in terms of geometry.

• Now, how to express the epipolar constraints algebraically?

Slide credit: Kristen Grauman

Page 63: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo geometry, with calibrated cameras

Main idea

Slide credit: Kristen Grauman

Page 64: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo geometry, with calibrated cameras

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.

Slide credit: Kristen Grauman

Page 65: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo geometry, with calibrated cameras

If the stereo rig is calibrated, we know : how to rotate and translate camera reference frame 1 to get to camera reference frame 2.

Slide credit: Kristen Grauman

Page 66: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

From geometry to algebra

TRXX' +=

TTRXTXT ×+×=ʹ×

RXT×=

( ) ( )RXTXXTX ×⋅ʹ=ʹ×⋅ʹ

0=Normal to the plane

Slide credit: Kristen Grauman

Page 67: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

From geometry to algebra

TRXX' +=

TTRXTXT ×+×=ʹ×

RXT×=

( ) ( )RXTXXTX ×⋅ʹ=ʹ×⋅ʹ

0=Normal to the plane

Slide credit: Kristen Grauman

Page 68: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

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.

Slide credit: Kristen Grauman

Page 69: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Matrix form of cross product

Can be expressed as a matrix multiplication.

cbbb

aaaaaa

ba !!!=

⎥⎥⎥

⎢⎢⎢

⎥⎥⎥

⎢⎢⎢

3

2

1

12

13

23

00

0

[ ]⎥⎥⎥

⎢⎢⎢

=

00

0

12

13

23

aaaaaa

ax

Slide credit: Kristen Grauman

Page 70: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Essential matrix

( ) 0=×⋅ʹ RXTX

( ) 0=⋅ʹ RXTX 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 the other image is constrained to lie on line defined by above. Note: these points are in camera coordinate systems.

Let RTE x=

0=ʹ EXX T

Page 71: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

x and x’ are scaled versions of X and X’

Page 72: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

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 the other image is constrained to lie on line defined by above.

Note: these points are in camera coordinate systems.

Let

pts x and x’ in the image planes are scaled versions of X and X’.

Page 73: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

0 0 0 0 0 d 0 –d 0

Essential matrix example: parallel cameras

For the parallel cameras, image of any point must lie on same horizontal line in each image plane.

Slide credit: Kristen Grauman

Page 74: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

image I(x,y) image I´(x´,y´)Disparity map D(x,y)

(x´,y´)=(x+D(x,y),y)

What about when cameras’ optical axes are not parallel?

Slide credit: Kristen Grauman

Page 75: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo image rectification: example

Source: Alyosha Efros

Page 76: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

Stereo image rectification

Reproject image planes onto a common plane parallel to the line between optical

centers Pixel motion is horizontal after this

transformation Two homographies (3x3 transforms), one for

each input image reprojection See Szeliski book, Sect. 2.1.5, Fig. 2.12, and

“Mapping from one camera to another” p. 56:

Adapted from Li Zhang

In practice, it is convenient if image scanlines (rows) are the epipolar lines.

Slide credit: Kristen Grauman

Page 77: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

77CSE 576, Spring 2008 Stereo matching

Your basic stereo algorithm

For each epipolar line For each pixel in the left image

• compare with every pixel on same epipolar line in right image

• pick pixel with minimum match cost

Improvement: match windows

Slide credit: Rick Szeliski

Page 78: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

78CSE 576, Spring 2008 Stereo matching

Image block matchingHow do we determine correspondences?

• block matching or SSD (sum squared differences)d is the disparity (horizontal motion)

How big should the neighborhood be?Slide credit: Rick Szeliski

Page 79: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

79CSE 576, Spring 2008 Stereo matching

Neighborhood size

Smaller neighborhood: more details Larger neighborhood: fewer isolated mistakes

w = 3 w = 20

Slide credit: Rick Szeliski

Page 80: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

80CSE 576, Spring 2008 Stereo matching

Matching criteria

Raw pixel values (correlation) Band-pass filtered images [Jones & Malik 92] “Corner” like features [Zhang, …] Edges [many people…] Gradients [Seitz 89; Scharstein 94] Rank statistics [Zabih & Woodfill 94]

Slide credit: Rick Szeliski

Page 81: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

81CSE 576, Spring 2008 Stereo matching

Local evidence framework

For every disparity, compute raw matching costsWhy use a robust function? • occlusions, other outliers

Can also use alternative match criteria

Slide credit: Rick Szeliski

Page 82: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

82CSE 576, Spring 2008 Stereo matching

Local evidence framework

Aggregate costs spatially

Here, we are using a box filter(efficient moving averageimplementation)

Can also use weighted average,[non-linear] diffusion…

Slide credit: Rick Szeliski

Page 83: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

83CSE 576, Spring 2008 Stereo matching

Local evidence framework

Choose winning disparity at each pixel

Interpolate to sub-pixel accuracy

d

E(d)

d*

Slide credit: Rick Szeliski

Page 84: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

84CSE 576, Spring 2008 Stereo matching

Active stereo with structured light

Project “structured” light patterns onto the object • simplifies the correspondence problem

camera 2

camera 1

projector

camera 1

projector

Li Zhang’s one-shot stereo

Slide credit: Rick Szeliski

Li Zhang, Brian Curless, and Steven M. Seitz. Rapid Shape Acquisition Using Color Structured Light and Multi-pass Dynamic Programming. In Proceedings of the 1st International Symposium on 3D Data Processing, Visualization, and Transmission (3DPVT), Padova, Italy, June 19-21, 2002, pp. 24-36.

Page 85: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

85CSE 576, Spring 2008 Stereo matching

Li Zhang, Brian Curless, and Steven M. Seitz

Page 86: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

86CSE 576, Spring 2008 Stereo matching

Page 87: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

87CSE 576, Spring 2008 Stereo matching

Page 88: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

88CSE 576, Spring 2008 Stereo matching

Page 89: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

89

Page 90: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

90

Page 91: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

91

Page 92: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

92CSE 576, Spring 2008 Stereo matching

BibliographyD. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo correspondence algorithms. International Journal of Computer Vision, 47(1):7-42, May 2002. R. Szeliski. Stereo algorithms and representations for image-based rendering. In British Machine Vision Conference (BMVC'99), volume 2, pages 314-328, Nottingham, England, September 1999. G. M. Nielson, Scattered Data Modeling, IEEE Computer Graphics and Applications, 13(1), January 1993, pp. 60-70. S. B. Kang, R. Szeliski, and J. Chai. Handling occlusions in dense multi-view stereo. In CVPR'2001, vol. I, pages 103-110, December 2001. Y. Boykov, O. Veksler, and Ramin Zabih, Fast Approximate Energy Minimization via Graph Cuts, Unpublished manuscript, 2000. A.F. Bobick and S.S. Intille. Large occlusion stereo. International Journal of Computer Vision, 33(3), September 1999. pp. 181-200 D. Scharstein and R. Szeliski. Stereo matching with nonlinear diffusion. International Journal of Computer Vision, 28(2):155-174, July 1998

Slide credit: Rick Szeliski

Page 93: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

93CSE 576, Spring 2008 Stereo matching

Volume Intersection • Martin & Aggarwal, “Volumetric description of objects from multiple views”, Trans.

Pattern Analysis and Machine Intelligence, 5(2), 1991, pp. 150-158. • Szeliski, “Rapid Octree Construction from Image Sequences”, Computer Vision,

Graphics, and Image Processing: Image Understanding, 58(1), 1993, pp. 23-32. Voxel Coloring and Space Carving

• Seitz & Dyer, “Photorealistic Scene Reconstruction by Voxel Coloring”, Proc. Computer Vision and Pattern Recognition (CVPR), 1997, pp. 1067-1073.

• Seitz & Kutulakos, “Plenoptic Image Editing”, Proc. Int. Conf. on Computer Vision (ICCV), 1998, pp. 17-24.

• Kutulakos & Seitz, “A Theory of Shape by Space Carving”, Proc. ICCV, 1998, pp. 307-314.

Bibliography

Slide credit: Rick Szeliski

Page 94: Lecture 11 - 6.869 Advances in Computer Vision, Fall 20176.869.csail.mit.edu/fa17/lecture/lecture12stereo... · Lecture 11 Geometry, Camera Calibration, and Stereo. 6.819 / 6.869:

94CSE 576, Spring 2008 Stereo matching

Related References • Bolles, Baker, and Marimont, “Epipolar-Plane Image Analysis: An Approach to

Determining Structure from Motion”, International Journal of Computer Vision, vol 1, no 1, 1987, pp. 7-55.

• Faugeras & Keriven, “Variational principles, surface evolution, PDE's, level set methods and the stereo problem", IEEE Trans. on Image Processing, 7(3), 1998, pp. 336-344.

• Szeliski & Golland, “Stereo Matching with Transparency and Matting”, Proc. Int. Conf. on Computer Vision (ICCV), 1998, 517-524.

• Roy & Cox, “A Maximum-Flow Formulation of the N-camera Stereo Correspondence Problem”, Proc. ICCV, 1998, pp. 492-499.

• Fua & Leclerc, “Object-centered surface reconstruction: Combining multi-image stereo and shading", International Journal of Computer Vision, 16, 1995, pp. 35-56.

• Narayanan, Rander, & Kanade, “Constructing Virtual Worlds Using Dense Stereo”, Proc. ICCV, 1998, pp. 3-10.

Bibliography

Slide credit: Rick Szeliski