course updates - ubc department of computer sciencelsigal/teaching/week_6_lecture_2.pdf ·...

43
Course Updates Rudimentary course webpage is available from: (look under teaching) Lecture notes, slides from last time and Assignment 2 are now posted Starter code for programming portion of Assignment 2 will be available in a day or two http://www.cs.toronto.edu/~ls/

Upload: others

Post on 27-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Course UpdatesRudimentary course webpage is available from:

(look under teaching)

Lecture notes, slides from last time and Assignment 2 are now posted

Starter code for programming portion of Assignment 2 will be available in a day or two

http://www.cs.toronto.edu/~ls/

Page 2: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera ModelsPart 2

Computer Graphics, CSCD18Fall 2007Instructor: Leonid Sigal

Page 3: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Last time …

Film

3D transformationsCamera models

Pinhole camera

Page 4: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Last time …3D transformationsCamera models

Pinhole cameraThin lens model

view planelens

z0

surface point

optical axis

z1

Page 5: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Last time …3D transformationsCamera models

Pinhole cameraThin lens modelRelationship between pinhole camera and thin lens model

view planelens

z0

surface point

optical axis

z1

Page 6: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Last time …

Virtual Film

ff

Film

3D transformationsCamera models

Pinhole cameraThin lens modelRelationship between pinhole camera and thin lens model

Conceptual pinhole camera

Page 7: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionUsing similar triangles:

[ ]zyx pppp =r

yp

f

ImagePlaney

zp

*yz

Pinhole

Page 8: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionUsing similar triangles:

[ ]zyx pppp =r

yp

f

ImagePlaney

zp

*yz

Pinhole

Page 9: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionUsing similar triangles:

[ ]zyx pppp =r

yp

f

ImagePlaney

zp

*yz

Pinhole

Page 10: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionUsing similar triangles:

yz

zy

ppfy

pf

py

=

=

*

*

[ ]zyx pppp =r

yp

f

ImagePlaney

zp

*yz

Pinhole

Page 11: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionUsing similar triangles:

yz

zy

ppfy

pf

py

=

=

*

*

xz

zx

ppfx

pf

px

=

=

*

*

[ ]zyx pppp =r

yp

f

ImagePlanex

zp

*xz

Pinhole

Page 12: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionWhat does prospective projection gives us?

Depth perception - objects that are far away appear smaller

Page 13: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective Projection Properties

Not a linear transformImportant properties

Lines are preserved Distances along the lines are notParallel lines are not preserved (vanishing point)

Page 14: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective Projection Properties

Vanishing Point

Not a linear transformImportant properties

Lines are preserved Distances along the lines are notParallel lines are not preserved (vanishing point)

Page 15: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective Projection Properties

Not a linear transformImportant properties

Lines are preserved Distances along the lines are notParallel lines are not preserved (vanishing point)

Page 16: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Orthographic Projection

f

zp

What if objects are sufficiently far away?

Rays almost perpendicularVariation in is insignificantFor both points

y*

zp∆

zp

ypy α≈* 60 feet

ImagePlane

y

z

Pinhole

Page 17: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

What do we really need to model to render the scene?

Scene with 3D objectsPosition and orientation of camera in the world coordinatesTransformation of objects from world to camera coordinatesProject the objects onto filmVisibility (with respect to the view volume)

No need to render everything, only things we can see

Page 18: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Position and Orientation of CameraIn general

Camera can be anywhere in the worldCamera can move as a function of time

How can we specify a camera coordinate frameWe need an origin (at the pinhole) – lets call it , and 3 unit vectors to define the camera coordinate frame

y

x

z

wre

ur

vr

wvu rrr ,,e

Bullet Time effect – Movie “The Matrix”

Page 19: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Position and Orientation of CameraHow can we specify a camera coordinate frame

We need an origin (at the pinhole) – lets call it , and 3 unit vectors to define the camera coordinate frame

How can we intuitively specify Let’s pick a point in the scene where we want to look, , then

Designate up direction , then

v must be perpendicular to

wtwtu rr

rrr

××

=

uwvrrr

×=

epepw

−−

=r

tr

p

wvu rrr ,,wvu rrr ,,

p

tr

y

x

z

wre

ur

vr

vu rr,

e

Page 20: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Position and Orientation of Camera

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?

y

x

z

wre

ur

vr

Page 21: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?Let’s try some points

y

x

z

wre

ur

vr

Camera Coordinates World Coordinates

( )0,0,0

Page 22: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?Let’s try some points

y

x

z

wre

ur

vr

Camera Coordinates World Coordinates

( )0,0,0( )f,0,0

e

Page 23: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?Let’s try some points

y

x

z

wre

ur

vr

Camera Coordinates World Coordinates

( )0,0,0( )f,0,0( )0,1,0

ewfer

+

Page 24: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?Let’s try some points

y

x

z

wre

ur

vr

Camera Coordinates World Coordinates

( )0,0,0( )f,0,0( )0,1,0( )f,1,0

e

ve r+

wfer

+

Page 25: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

Now that we have a camera defined in world coordinate frame, how do we take a point in the camera coordinate frame and map to the world coordinate frame?Let’s try some points

y

x

z

wre

ur

vr

Camera Coordinates World Coordinates

( )0,0,0( )f,0,0( )0,1,0( )f,1,0

e

ve r+

wfverr

++

wfer

+

Page 26: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

It’s relatively easy to show that any point in camera coordinate frame can be expressed in world coordinate frame using the following homogenized transformation:

See lecture notes for details

ccw

w pMp =

⎥⎦

⎤⎢⎣

⎡=

1]0,0,0[],,[ ewvu

Mcw

rrr

Page 27: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Camera to World Transformation

It’s relatively easy to show that any point in camera coordinate frame can be expressed in world coordinate frame using the following homogenized transformation:

Actually, what we need is the inverse:

ccw

w pMp =

wwc

c pMp =

Page 28: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Inverting the Camera to World Transformation

We have:

⎥⎥⎥

⎢⎢⎢

↓↓↓

↑↑↑= wvuA rrr

⎥⎦

⎤⎢⎣

⎡=

1]0,0,0[eA

Mcwc

cww pMp =

We want:

wwc

c pMp =

Page 29: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Inverting the Camera to World Transformation

We have:

⎥⎥⎥

⎢⎢⎢

↓↓↓

↑↑↑= wvuA rrr

⎥⎦

⎤⎢⎣

⎡=

1]0,0,0[eA

Mcwc

cww pMp =

( )epApepAp

wc

cw

−=

+=−1

We want:

wwc

c pMp =

Page 30: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Inverting the Camera to World Transformation

ccw

w pMp = ⎥⎦

⎤⎢⎣

⎡=

1]0,0,0[eA

Mcw⎥⎥⎥

⎢⎢⎢

↓↓↓

↑↑↑= wvuA rrr

( )epApepAp

wc

cw

−=

+=−1

Since A is orthonormal (easy to check), the inverse of A is simply a transpose

( )eApAp

epApTwTc

wTc

−=

−=

We have:

We want:

wwc

c pMp =

Page 31: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Inverting the Camera to World Transformation

ccw

w pMp = ⎥⎦

⎤⎢⎣

⎡=

1]0,0,0[eA

Mcw⎥⎥⎥

⎢⎢⎢

↓↓↓

↑↑↑= wvuA rrr

( )epApepAp

wc

cw

−=

+=−1

Since A is orthonormal (easy to check), the inverse of A is simply a transpose

( )eApAp

epApTwTc

wTc

−=

−=

wwc

c pMp = ⎥⎦

⎤⎢⎣

⎡ −=

1]0,0,0[eAA

MTT

wc⎥⎥⎥

⎢⎢⎢

→←→←→←

=wvu

AT

r

r

r

We have:

We want:

Page 32: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective Projection (Again)

Earlier we derive perspective projection using similar trianglesNow, we will go through an exercise of doing it algebraically (it’s a good exercise)

y

x

z

wre

ur

vr

Page 33: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionLets consider everything in the camera coordinate frame

)0()( −= cpr λλ

)1,0,0(=nr),0,0( ff =

( )0,0,0=e *x

f

( ) 0=⋅− nfxc r

cp

pinhole

Equation of the image plane (film)

Page 34: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectionLets consider everything in the camera coordinate frame

)0()( −= cpr λλ

)1,0,0(=nr),0,0( ff =

( )0,0,0=e *x

f

( ) 0=⋅− nfxc r

If we solve for that satisfies the plane equation,we get

( ) ⎟⎟⎠

⎞⎜⎜⎝

⎛== 1,,**

cz

cy

cz

cx

pp

ppfrx λ

cp

pinhole

Equation of the image plane (film)

Page 35: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Perspective ProjectioncpThe mapping from a point in camera

coordinates to point in the image ( )1,, ** yxplane, is what we will call the perspective projection

( ) ⎟⎟⎠

⎞⎜⎜⎝

⎛== 1,,**

cz

cy

cz

cx

pp

ppfrx λ

Just a scaling factor, we can ignore

Page 36: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous PerspectiveThe mapping of point to

is the form of scaling transformation,but since it depends on the depth of the point , it is not linear (remember the tapering example from last class)

It would be very useful if we can express this non-linear transformation as a linear transformation (matrix). Why?

( )cz

cy

cx

c pppp ,,=( )1,, *** yxx =

czp

Page 37: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous Perspective

czp

( )cz

cy

cx

c pppp ,,=( )1,, *** yxx =

wwcp pMMx =*

The mapping of point to is the form of scaling transformation,

but since it depends on the depth of the point , it is not linear (remember the tapering example from last class)

It would be very useful if we can express this non-linear transformation as a linear transformation (matrix). Why?

Page 38: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous Perspective

We can express it a a linear transformation in homogeneous coordinates (this is one of the benefits of using homogeneous coordinates!)Here’s the transformation that does what we want:

Let’s prove this is true

⎥⎥⎥⎥

⎢⎢⎢⎢

=

0/100010000100001

f

M p

Page 39: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous Perspective

Claim:

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

⎥⎥⎥⎥

⎢⎢⎢⎢

==

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

10/100010000100001

11//

11

*

*

cz

cy

cx

cp

cz

cy

cz

cx

ppp

f

pMpppp

fyx

f

Page 40: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous Perspective

Claim:

Proof:

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

⎥⎥⎥⎥

⎢⎢⎢⎢

==

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

10/100010000100001

11//

11

*

*

cz

cy

cx

cp

cz

cy

cz

cx

ppp

f

pMpppp

fyx

f

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

fpppp

ppp

f cz

cz

cy

cx

cz

cy

cx

/10/100010000100001

Point in homogeneous coordinates can be scaled arbitrarily

Page 41: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Homogeneous Perspective

Claim:

Proof:

⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜

⎥⎥⎥⎥

⎢⎢⎢⎢

==

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎟⎟⎟

⎜⎜⎜

10/100010000100001

11//

11

*

*

cz

cy

cx

cp

cz

cy

cz

cx

ppp

f

pMpppp

fyx

f

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

1

//

/

/10/100010000100001

fpfppfp

fp

fpppp

ppp

f

cz

cy

cz

cx

cz

cz

cz

cy

cx

cz

cy

cx

Point in homogeneous coordinates can be scaled arbitrarily

Page 42: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

Putting together a camera model

Projecting a world point to image (film) planew

wcp pMMx =*

wTT

peAA

f

x ⎥⎦

⎤⎢⎣

⎡ −

⎥⎥⎥⎥

⎢⎢⎢⎢

=1]0,0,0[

0/100010000100001

*

⎥⎥⎥

⎢⎢⎢

→←→←→←

=wvu

AT

r

r

r

y

x

z

wre

ur

vr

where

Page 43: Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf · Perspective Projection The mapping from a point in camera pc coordinates to point in the

PseudodepthWe would like to change the projection transform so that z-component of the projection gives us useful information (not just a constant f )We want it to encode something about depth of a point. Why?

( )0,0,0=e *x

cp

pinhole

Z-buffering