Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf ·...
Transcript of Course Updates - UBC Department of Computer Sciencelsigal/teaching/Week_6_Lecture_2.pdf ·...
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/
Camera ModelsPart 2
Computer Graphics, CSCD18Fall 2007Instructor: Leonid Sigal
Last time …
Film
3D transformationsCamera models
Pinhole camera
Last time …3D transformationsCamera models
Pinhole cameraThin lens model
view planelens
z0
surface point
optical axis
z1
Last time …3D transformationsCamera models
Pinhole cameraThin lens modelRelationship between pinhole camera and thin lens model
view planelens
z0
surface point
optical axis
z1
Last time …
Virtual Film
ff
Film
3D transformationsCamera models
Pinhole cameraThin lens modelRelationship between pinhole camera and thin lens model
Conceptual pinhole camera
Perspective ProjectionUsing similar triangles:
[ ]zyx pppp =r
yp
f
ImagePlaney
zp
*yz
Pinhole
Perspective ProjectionUsing similar triangles:
[ ]zyx pppp =r
yp
f
ImagePlaney
zp
*yz
Pinhole
Perspective ProjectionUsing similar triangles:
[ ]zyx pppp =r
yp
f
ImagePlaney
zp
*yz
Pinhole
Perspective ProjectionUsing similar triangles:
yz
zy
ppfy
pf
py
=
=
*
*
[ ]zyx pppp =r
yp
f
ImagePlaney
zp
*yz
Pinhole
Perspective ProjectionUsing similar triangles:
yz
zy
ppfy
pf
py
=
=
*
*
xz
zx
ppfx
pf
px
=
=
*
*
[ ]zyx pppp =r
yp
f
ImagePlanex
zp
*xz
Pinhole
Perspective ProjectionWhat does prospective projection gives us?
Depth perception - objects that are far away appear smaller
Perspective Projection Properties
Not a linear transformImportant properties
Lines are preserved Distances along the lines are notParallel lines are not preserved (vanishing point)
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)
Perspective Projection Properties
Not a linear transformImportant properties
Lines are preserved Distances along the lines are notParallel lines are not preserved (vanishing point)
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
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
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”
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
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
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
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
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
+
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
+
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
+
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
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 =
Inverting the Camera to World Transformation
We have:
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
↓↓↓
↑↑↑= wvuA rrr
⎥⎦
⎤⎢⎣
⎡=
1]0,0,0[eA
Mcwc
cww pMp =
We want:
wwc
c pMp =
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 =
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 =
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:
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
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)
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)
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
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
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?
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
Homogeneous Perspective
Claim:
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
==
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎟⎟⎟
⎠
⎞
⎜⎜⎜
⎝
⎛
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎟⎟⎟
⎠
⎞
⎜⎜⎜
⎝
⎛
10/100010000100001
11//
11
*
*
cz
cy
cx
cp
cz
cy
cz
cx
ppp
f
pMpppp
fyx
f
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
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
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
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