Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera...

34
CSE486, Penn State Robert Collins Lecture 12: Camera Projection Reading: T&V Section 2.4

Transcript of Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera...

Page 1: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Lecture 12: Camera Projection

Reading: T&V Section 2.4

Page 2: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Imaging Geometry

VU

W

Object of Interestin World CoordinateSystem (U,V,W)

Page 3: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Imaging Geometry

Z

f

Camera Coordinate System (X,Y,Z).

• Z is optic axis• Image plane located f units

out along optic axis• f is called focal length

X

Y

Page 4: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Imaging Geometry

VU

W

Z

Forward Projection onto image plane.3D (X,Y,Z) projected to 2D (x,y)

y

xX

Y

Page 5: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Imaging Geometry

VU

W

Zy

Our image gets digitizedinto pixel coordinates (u,v)

xX

Y

u

v

Page 6: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Imaging Geometry

VU

W

Zy

World Coordinates

CameraCoordinates

Image (film)Coordinates

PixelCoordinates

u

v

xX

Y

Page 7: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Forward Projection

UVW

XYZ

xy

uv

WorldCoords

CameraCoords

FilmCoords

PixelCoords

We want a mathematical model to describehow 3D World points get projected into 2DPixel coordinates.

Our goal: describe this sequence of transformations by a big matrix equation!

Page 8: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Backward Projection

UVW

XYZ

xy

uv

WorldCoords

CameraCoords

FilmCoords

PixelCoords

Note, much of vision concerns trying toderive backward projection equations torecover 3D scene structure from images (via stereo or motion)

But first, we have to understand forward projection…

Page 9: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Forward Projection

UVW

XYZ

xy

uv

WorldCoords

CameraCoords

FilmCoords

PixelCoords

3D-to-2D Projection• perspective projection

We will start here in the middle, since we’ve alreadytalked about this when discussing stereo.

Page 10: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Basic Perspective Projection

XX

YY

ZZff

OO

p = p = (x,y,f)

xx

yy

Z

Yfy

Z

Xfx

O.Camps, PSU

Z

P =P = (X,Y,Z)

y

Scene Point

Image Point

Perspective Projection Eqns

YX

x

Page 11: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Basic Perspective Projection

XX

YY

ZZff

OO

p = p = (x,y,f)

xx

yy

Z

Yfy

Z

Xfx

O.Camps, PSU

X

Z

P =P = (X,Y,Z)

x y

Scene Point

Image Point

Perspective Projection Eqns

Y

Xx

Zf

derived via similar triangles rule

Page 12: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Basic Perspective Projection

XX

YY

ZZff

OO

p = p = (x,y,f)

xx

yy

Z

Yfy

Z

Xfx

O.Camps, PSU

X

Z

P =P = (X,Y,Z)

x y

Scene Point

Image Point

Perspective Projection Eqns

Y

Xx

Zf

Z

Yyf

derived via similar triangles rule

Page 13: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Basic Perspective Projection

XX

YY

ZZff

OO

p = p = (x,y,f)

xx

yy

Z

Yfy

Z

Xfx

O.Camps, PSU

X

Z

P =P = (X,Y,Z)

x y

Scene Point

Image Point

Perspective Projection Eqns

Y

So how do we represent this as a matrix equation? We need to introduce homogeneous coordinates.

Page 14: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Homogeneous Coordinates

Represent a 2D point (x,y) by a 3D point (x’,y’,z’) byadding a “fictitious” third coordinate.

By convention, we specify that given (x’,y’,z’) we canrecover the 2D point (x,y) as

'

'

'

'

z

yy

z

xx

Note: (x,y) = (x,y,1) = (2x, 2y, 2) = (k x, ky, k) for any nonzero k (can be negative as well as positive)

Page 15: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Perspective Matrix Equation(in Camera Coordinates)

10

0

0

1

0

0

0

0

0

0

'

'

'

Z

Y

X

f

f

z

y

x

Z

Yfy

Z

Xfx

Page 16: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Forward Projection

UVW

XYZ

xy

uv

WorldCoords

CameraCoords

FilmCoords

PixelCoords

Rigid Transformation (rotation+translation)between world and camera coordinate systems

Page 17: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

World to Camera Transformation

XX

YY

ZZ

PC

UU

VV

WWPW

Avoid confusion: Pw and Pc are not two different points. They are the same physical point, described in two different coordinate systems.

Page 18: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

World to Camera Transformation

XX

YY

ZZ

PC

UU

VV

WWPW

Translate by - C (align origins)

CRotate toalign axes

R

PC = R ( PW - C )

Page 19: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Matrix Form, Homogeneous Coords

PC = R ( PW - C )

1000

10

01

00

z

y

x

c

c

c

0

0

1

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

Page 20: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Example: Simple Stereo System

X

Y Z

located atlocated at(0,0,0)(0,0,0)

leftcamera

zz

xx

yy

(X,Y,Z)

TTxx

rightcameralocated atlocated at(T(Txx,0,0),0,0)

zz

xx

yy( , )

( , )

Left camera located at world origin (0,0,0)and camera axes aligned with world coord axes.

Page 21: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

1000

10

01

00

z

y

x

c

c

c

0

0

1

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

1

W

V

U

Simple Stereo, Left Camera

1 0 00 1 00 0 1

camera axes alignedwith world axes

000

located at world position (0,0,0)

=

Page 22: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Simple Stereo Projection Equations

Left camera

Page 23: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Example: Simple Stereo System

X

Y Z

located atlocated at(0,0,0)(0,0,0)

leftcamera

zz

xx

yy

(X,Y,Z)

TTxx

rightcameralocated atlocated at(T(Txx,0,0),0,0)

zz

xx

yy( , )

( , )

Right camera located at world location (Tx,0,0)and camera axes aligned with world coord axes.

Page 24: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

1000

10

01

00

z

y

x

c

c

c

0

0

1

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

1

W

V

U

Simple Stereo, Right Camera

1 0 00 1 00 0 1

camera axes alignedwith world axes

-Tx

00

located at world position (Tx,0,0)

=

Page 25: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Right camera

Simple Stereo Projection Equations

Left camera

Page 26: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins Bob’s sure-fire way(s) to

figure out the rotation

1000

10

01

00

z

y

x

c

c

c

0

0

1

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

PC = R PW

forget about thiswhile thinkingabout rotations

This equation says how vectors in the world coordinate system (including the coordinate axes) get transformed into the camera coordinate system.

Page 27: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Figuring out Rotations

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

PC = R PW

what if world x axis (1,0,0) corresponds to camera axis (a,b,c)?

1WVU

1000

r13r12r11

r23r22r21

r33r32r311ZYX 1

00

abc

1WVU

1000

r13r12r11

r23r22r21

r33r32r311ZYX 1

00

abc

abc

we can immediately write down the first column of R!

Page 28: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Figuring out Rotations

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

and likewise with world Y axis and world Z axis...

axis is world coordssame axis in camera coords

world X axis (1,0,0)in camera coords

world Y axis (0,1,0)in camera coords

world Z axis (0,0,1)in camera coords

Page 29: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Figuring out Rotations

1

W

V

U

1000

r31r21r11

r32r22r12

r33r23r13

1

Z

Y

X

Alternative approach: sometimes it is easier to specifywhat camera X,Y,or Z axis is in world coordinates. Thendo rearrange the equation as follows.

PC = R PW R-1PC = PW RTPC = PW

Page 30: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Figuring out Rotations

what if camera X axis (1,0,0) corresponds to world axis (a,b,c)?

1

W

V

U

1000

r31r21r11

r32r22r12

r33r23r13

1

Z

Y

X

RTPC = PW

1WVU

1000

r31r21r11

r32r22r12

r33r23r13

1ZYX100

abc

we can immediately write down the first column of RT,(which is the first row of R).

1WVU

1000

r31r21r11

r32r22r12

r33r23r13

1ZYX100

abc

abc

Page 31: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Figuring out Rotations

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

and likewise with camera Y axis and camera Z axis...

axis is world coordssame axis in camera coords

camera X axis (1,0,0)in world coords

camera Y axis (0,1,0)in world coords

camera Z axis (0,0,1)in world coords

Page 32: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Example

x

yz

0 0 10 -1 01 0 0

Rtrain

0 -1 00 0 1-1 0 0

Rfly

Page 33: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins Note: External Parameters

also often written as R,T

1000

10

01

00

z

y

x

c

c

c

0

0

1

1

W

V

U

1000

r13r12r11

r23r22r21

r33r32r31

1

Z

Y

X

tx

1000

r13r12r11

r23r22r21

r33r32r31

ty

tz

R ( PW - C )

= R PW - R C

= R PW + T

Page 34: Lecture 12: Camera Projection - Pennsylvania Statertc12/CSE486/lecture12.pdf · Lecture 12: Camera Projection Reading: T&V Section 2.4. CSE486, ... and likewise with world Y axis

CSE486, Penn StateRobert Collins

Summary

UVW

XYZ

xy

uv

WorldCoords

CameraCoords

FilmCoords

PixelCoords

We now know how to transform 3D world coordinate points into camera coords, and then do perspective project to get 2D pointsin the film plane.

Next time: pixel coordinates