Lecture 7: Camera Models - Artificial...

43
Lecture 7 - Fei-Fei Li Lecture 7: Camera Models Professor FeiFei Li Stanford Vision Lab 15Oct11 1

Transcript of Lecture 7: Camera Models - Artificial...

Page 1: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

Lecture 7: Camera Models

Professor Fei‐Fei LiStanford Vision Lab

15‐Oct‐111

Page 2: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

What we will learn today?

• Pinhole cameras• Cameras & lenses• The geometry of pinhole cameras

15‐Oct‐112

Reading: [FP] Chapters 1 – 3[HZ] Chapter 6

Page 3: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

What we will learn today?

• Pinhole cameras• Cameras & lenses• The geometry of pinhole cameras

15‐Oct‐113

Reading: [FP] Chapters 1 – 3[HZ] Chapter 6

Page 4: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐114

How do we see the world?

• Let’s design a camera– Idea 1:  put a piece of film in front of an object– Do we get a reasonable image?

Page 5: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐115

Pinhole camera

• Add a barrier to block off most of the rays– This reduces blurring– The opening known as the aperture

Page 6: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐116

Some history…

Milestones: • Leonardo da Vinci (1452‐1519): first record of camera obscura• Johann Zahn (1685): first portable camera

Page 7: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐117

Some history…

Photography (Niepce, “La Table Servie,” 1822)

Milestones: • Leonardo da Vinci (1452‐1519): first record of camera obscura• Johann Zahn (1685): first portable camera• Joseph Nicephore Niepce (1822): first photo  ‐ birth of photography

• Daguerréotypes (1839)• Photographic Film (Eastman, 1889)• Cinema (Lumière Brothers, 1895)• Color Photography (Lumière Brothers, 1908)

Page 8: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐118

Some history…

Motzu(468‐376 BC)

Aristotle(384‐322 BC)

Also: Plato, Euclid

Al‐Kindi (c. 801–873) Ibn al‐Haitham (965‐1040)Oldest existent book 

on geometry in China

Page 9: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐119

Pinhole camera

zyfy

zxfx

''

''

yx

P

zyx

P

Derived using similar triangles

Note: z is always negative.

Page 10: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1110

Pinhole camera

O

P = [x, z]

P’=[x’, f’]

f’

zx

fx

'

x

z

Page 11: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1111

Pinhole camera

• Common to draw image plane in front of the focal point  • Moving the image plane merely scales the image.

f f

zyf'y

zxf'x

Page 12: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1112

Pinhole camera

Kate lazuka ©

Is the size of the aperture important? 

Page 13: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1113

Cameras & Lenses

Shrinkingaperturesize

‐ Rays are mixed up

Adding lenses!‐Why the aperture cannot be too small?

‐Less light passes through‐Diffraction effect

Page 14: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1114

Cameras & Lenses

• A lens focuses light onto the film

Page 15: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1115

Cameras & Lenses

• A lens focuses light onto the film– Rays passing through the center are not deviated– All parallel rays converge to one point on a plane located at the focal 

length f

focal point

f

Page 16: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1116

Cameras & Lenses

• A lens focuses light onto the film– There is a specific distance at which objects are “in focus”

[other points project to a “circle of confusion” in the image]

“circle of confusion”

Page 17: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

Cameras & Lenses• Laws of geometric optics

– Light travels in straight lines in homogeneous medium– Reflection upon a surface: incoming ray, surface normal, 

and reflection are co‐planar– Refraction: when a ray passes from one medium to 

another

15‐Oct‐1117

Snell’s law

n1 sin1 = n2 sin 2

1 = incident angle2 = refraction angleni = index of refraction 

Page 18: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1118

Thin Lenses

Snell’s law:

n1 sin1 = n2 sin 2

Small angles:n1 1 n2 2 

n1 = n (lens)n1 = 1 (air)

zo

zy'z'y

zx'z'x

ozf'z

)1n(2Rf

Page 19: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1119

Cameras & Lenses

Source wikipedia

Page 20: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1120

Issues with lenses: Chromatic Aberration

• Lens has different refractive indices for different wavelengths: causes color fringing

)1n(2Rf

Page 21: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1121

Issues with lenses: Chromatic Aberration

• Rays farther from the optical axis focus closer

Page 22: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1122

Issues with lenses: Chromatic Aberration

No distortion

Pin cushion

Barrel (fisheye lens)

– Deviations are most noticeable for rays that pass through the edge of the lens

Image magnification decreases with distance from the optical axis

Page 23: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

What we will learn today?

• Pinhole cameras• Cameras & lenses• The geometry of pinhole cameras

15‐Oct‐1123

Page 24: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1124

Pinhole cameraf

f = focal lengthc = center of the camera

c

)zyf,

zxf()z,y,x(

2E

3

Page 25: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1125

Pinhole camera

No — division by z is nonlinear!

)zyf,

zxf()z,y,x(

Is this a linear transformation?

How to make it linear?

Page 26: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1126

Homogeneous coordinates

homogeneous image coordinates

homogeneous scene coordinates

• Converting from homogeneous coordinates

Page 27: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1127

Homogeneous coordinates

10100000000

'zyx

ff

zyfxf

P

zyfzxf

'iP

PMP '

M3

H4

Perspective Projection Transformation:“Projection matrix”

Page 28: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1128

From retina plane to images

Pixels, bottom‐left coordinate systems

Page 29: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1129

From retina plane to images

)czyf,c

zxf()z,y,x( yx

1. Off set

x

y

xc

yc

C=[cx, cy]

Page 30: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1130

From retina plane to images

),(),,( yx czylfc

zxkfzyx

1. Off set2. From metric to pixels

x

y

xc

yc

C=[cx, cy] Units: k,l : pixel/m

f  : m : pixel, Non‐square pixels

Page 31: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1131

From retina plane to images

Matrix form?x

y

xc

yc

C=[cx, cy]

)czy,c

zx()z,y,x( yx

Page 32: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1132

Camera matrix

x

y

xc

yc

C=[cx, cy]

)czy,c

zx()z,y,x( yx

101000000

'zyx

cc

zzcyzcx

P y

x

y

x

Page 33: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1133

Camera matrix

x

y

xc

yc

C=[cx, cy]

)czy,c

zx()z,y,x( yx

101000000

'zyx

cc

P y

x

Page 34: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1134

Camera matrix

)czy,c

zx()z,y,x( yx

x

y

xc

yc

C=[cx, cy]

Skew parameter

10100000

'zyx

ccs

P y

x

Page 35: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1135

Camera matrix

PMP '

PIK 0

10100000

'zyx

ccs

P y

x

Camera matrix K

K has 5 degrees of freedom!

Page 36: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1136

Camera & world reference system

Ow

iw

kw

jwR,T

•The mapping is defined within the camera reference system

• What if an object is represented in the world reference system?

Page 37: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1137

Camera & world reference system

Ow

iw

kw

jwR,T

wPMP ' wPTRK

wPTRP In 4D homogeneous coordinates:

Internal parameters External parameters

Page 38: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1138

Projective cameras

How many degrees of freedom?5 + 3 + 3 =11!

100c0cs

K y

x

Ow

iw

kw

jwR,T

wPMP 13' 144333 wPTRK

Page 39: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1139

Projective cameras

Ow

iw

kw

jwR,T

),(),,(3

2

3

1

w

w

w

ww P

PPPzyx

mm

mm

M is defined up to scale!Multiplying M by a scalarwon’t change the image

wPMP 13' 144333 wPTRK

3

2

1

mmm

M

Page 40: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1140

Theorem (Faugeras, 1993) ][ bATKRKTRKM

3

2

1

aaa

A

1000 y

x

ccs

K

lf;kf

Page 41: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1141

Properties of Projection•Points project to points•Lines project to lines

Page 42: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li 15‐Oct‐1142

Properties of ProjectionVanishing point•Angles are not preserved

•Parallel lines meet

Page 43: Lecture 7: Camera Models - Artificial Intelligencevision.stanford.edu/teaching/cs231a_autumn1112/... · Fei-Fei Li Lecture 7 - Cameras & Lenses • Laws of geometric optics – Light

Lecture 7 -Fei-Fei Li

What we have learned today?

• Pinhole cameras• Cameras & lenses• The geometry of pinhole cameras

15‐Oct‐1143

Reading: [FP] Chapters 1 – 3[HZ] Chapter 6