3CG 2006 1 / 1
B4 Computational Geometry
David Murray
[email protected]/∼dwm/Courses/3CG
Michaelmas 2006
3CG 2006 2 / 1
Vanishing points and horizons. Applications ofprojective transformations
Lecture 1: Euclidean, similarity, affine and projectivetransformations. Homogeneous coordinates and matrices.Coordinate frames.
Lecture 2Perspective projection and its matrix representation.Vanishing points.Applications of projective transformations.
Lecture 3: Convexity of point-sets, convex hull and algorithms.Conics and quadrics, implicit and parametric forms, computationof intersections.Lecture 4: Bezier curves, B-splines. Tensor-product surfaces.
3CG 2006 3 / 1
Recall: Perspective (central) projection — 3D to 2D
The camera modelMathematical idealized camera3D→ 2D• Image coordinates xy• Camera frame XYZ (origin atoptical centre)• Focal length f , image plane isat Z = f .Similar triangles
xf=
XZ
yf=
YZ
or x = fXZ
where x and X are 3-vectors, withx = (x , y , f )>, X = (X ,Y ,Z )>.
3CG 2006 4 / 1
Vanishing Points
3CG 2006 5 / 1
Vanishing Points in 1D and 2D
3CG 2006 6 / 1
All parallel lines meet at the same vanishing point
A line of 3D points isrepresentedas
X(λ) = A + λD
Using x = fX/Z the vanishingpoint of its image is
v = limλ→±∞
x(λ) = fA + λD
AZ + λDZ
= fD
DZ= f
DX/DZDY/DZ
1
• v depends only on thedirection D, not on A.• Parallel lines have the samevanishing point.
3CG 2006 7 / 1
The Homogeneous 3× 4 Projection Matrix
x = fXZ
Choose f = 1 from now on.
Homogeneous image coordinates (x1, x2, x3)> correctly represent
x = X/Z if
x1x2x3
P=
1 0 0 00 1 0 00 0 1 0
XYZ1
= [I | 0](
X1
)
because thenx =
x1
x3=
XZ
y =x2
x3=
YZ
Then perspective projection is a linear map, represented by a 3× 4projection matrix, from 3D to 2D.
3CG 2006 8 / 1
Vanishing points using homogeneous notation
A line of points in 3D through the point A with direction D is
X(µ) P= A + µD
Writing this in homogeneous notationX1(µ)X2(µ)X3(µ)X4(µ)
P=
(A1
)+ µ
(D0
)P=
1µ
(A1
)+
(D0
)
In the limit µ→∞ the point on the line is
(D0
)So, homogeneous vectors with X4 = 0 represent points “atinfinity”.Points at infinity are equivalent to directions
3CG 2006 9 / 1
Vanishing points using homogeneous notation: EgThe vanishing point of a line with direction D is the image of thepoint at∞
v =
1 0 0 00 1 0 00 0 1 0
( D0
)=
DXDYDZ
Exercise: Compute the vanishing points of lines on an XZplane:(1) parallel to the Z axis; (2) at 45◦ to the Z axix; (3) parallel tothe X axis.
1:
0010
→ 0
01
2:
1010
→ 1
01
3:
1000
→ 1
00
3CG 2006 10 / 1
The advantages of homogeneous notation ...
There are two advantages of using homogeneous notation torepresent perspective projection:
1 Non-linear projections equations are turned into linear equations.The tools of linear algebra can then be used.
2 Vanishing points are treated naturally, and awkward limitingprocedures are then avoided.
3CG 2006 11 / 1
Plane to Plane Projective Transformations
x1x2x3
= P
X1X2X3X4
Choose the world coordinate system such that the world plane haszero Z coordinate. Then the 3× 4 matrix P reduces to a 3× 3 planeto plane projective transformation.
x1x2x3
=
p11 p12 p13 p14p21 p22 p23 p24p31 p32 p33 p34
XY01
=
p11 p12 p14p21 p22 p24p31 p32 p34
XY1
• This is the most general transformation between the world planeand image plane under imaging by a perspective camera.• A plane-plane projective transformation is also called anhomography or a collineation.
3CG 2006 12 / 1
Computing planar transformations
How many pointcorrespondences are required tocompute a Euclideantransformation of the plane?
How many pointcorrespondences are required tocompute a similaritytransformation of the plane?
3CG 2006 13 / 1
Computing a projective transformation x ′1x ′2x ′3
P=
h11 h12 h13h21 h22 h23h31 h32 h33
x1x2x3
P= Hx
where H is a 3× 3 non-singularhomogeneous matrix withEIGHT dof.
Each point correspondence gives two constraints
x ′ =x ′1x ′3
=h11x + h12y + h13
h31x + h32y + h33, y ′ =
x ′2x ′3
=h21x + h22y + h23
h31x + h32y + h33
Multiplying out give two equations linear in the elements of H
x ′ (h31x + h32y + h33) = h11x + h12y + h13
y ′ (h31x + h32y + h33) = h21x + h22y + h23
3CG 2006 14 / 1
Simple ExampleSuppose the correspondences (x , y)↔ (x ′, y ′) are known for fourpoints (no three collinear), then H is determined uniquely.
1st correspondence(0,0)→ (0,0)
λ1
001
=
h11 h12 h13h21 h22 h23h31 h32 h33
001
=
h13h23h33
Whence h13 = h23 = 0.
2nd correspondence(1,0)→ (1,0)
λ2
101
=
h11 h12 0h21 h22 0h31 h32 h33
101
=
h11h21
h31 + h33
Whence
h21 = 0 and h11 = h31 + h33
3CG 2006 15 / 1
Simple example Continued
3rd correspondence (0,1)→ (0,1) gives h12 = 0 andh22 = h32 + h33.4th correspondence (1,1)→ (2,1)
λ4
211
=
h31 + h33 0 00 h32 + h33 0
h31 h32 h33
111
=
h31 + h33h32 + h33
h31 + h32 + h33
Take ratios⇒ 2 equations in 3 unknowns⇒ solve for ratio of matrixelements only.
H = λ
2 0 00 1 00 −1 2
P=
2 0 00 1 00 −1 2
3CG 2006 16 / 1
Computational Algorithm
The equations,
x ′ (h31x + h32y + h33) = h11x + h12y + h13
y ′ (h31x + h32y + h33) = h21x + h22y + h23
can be rearranged as[x y 1 0 0 0 −x ′x −x ′y −x ′
0 0 0 x y 1 −y ′x −y ′y −y ′
]h = 0
where h = (h11,h12,h13,h21,h22,h23,h31,h32,h33)> is the matrix H
written as a 9-vector.
3CG 2006 17 / 1
continued ...
For 4 points,
x1 y1 1 0 0 0 −x ′1x1 −x ′1y1 −x ′10 0 0 x1 y1 1 −y ′1x1 −y ′1y1 −y ′1x2 y2 1 0 0 0 −x ′2x2 −x ′2y2 −x ′20 0 0 x2 y2 1 −y ′2x2 −y ′2y2 −y ′2x3 y3 1 0 0 0 −x ′3x3 −x ′3y3 −x ′30 0 0 x3 y3 1 −y ′3x3 −y ′3y3 −y ′3x4 y4 1 0 0 0 −x ′4x4 −x ′4y4 −x ′40 0 0 x4 y4 1 −y ′4x4 −y ′4y4 −y ′4
h = 0
which has the form Ah = 0, with A a 8× 9 matrix. The solution h isthe (one dimensional) null space of A.If using many points, one can use least squares. Solution best foundthen using SVD of A — ie USV> ← A Then h is the column of Vcorresponding to smallest singular value. (The smallest singularvalue would be zero of all the data were exact ...)
3CG 2006 18 / 1
Some Matlabnpoints = 4 (or 5 later -- 5th point is noisy)x = [0,1,0,1, 1.01]; y = [0,0,1,1, 0.99];xd = [0,1,0,2, 2.01]; yd = [0,0,1,1, 1.01];A = zeros(2*npoints,9);for i=1:npoints,A(2*i-1,:)= [x(i),y(i),1,0,0,0, -x(i)*xd(i),-xd(i)*y(i),-xd(i)];A(2*i, :)= [0,0,0,x(i),y(i),1, -x(i)*yd(i),-yd(i)*y(i),-yd(i)];
end;if npoints==4
h = null(A);else
[U,S,V] = svd(A);h=V(:,9);
end;H=[h(1),h(2),h(3);h(4),h(5),h(6);h(7),h(8),h(9);]
With the 4 exact points ...H = 0.6325 −0.0000 0.0000
0.0000 0.3162 −0.00000.0000 −0.3162 0.6325
Adding the noisy point ...H = 0.6295 −0.0000 −0.0000−0.0001 0.3188 0.0001−0.0050 −0.3155 0.6344
3CG 2006 19 / 1
♣ 1: Removing Perspective DistortionObjective: Back project to world plane1. Find Euclidean coordinates of 4 points on the flat object plane(xi , yi)
>.2. Measure the corresponding image coordinates of these 4 points(x ′i , y
′i )>.
3. Compute H from the 4 (xi , yi)> ↔ (x ′i , y
′i )>.
4. Euclidean coords of any image point are(x , y ,1)> = H−1(x ′, y ′,1)>.
The image can be warped onto the world plane using H. How?
3CG 2006 20 / 1
♣ 2: Mosaicing from rotated image planes
An image is the intersection of a plane with the cone of raysbetween points in 3-space and the optical centre. Any two such“images” (with the same optical centre) are related by a planarprojective transformation.
X
x
x
1
2
As the camera is rotated the points of intersection of the rays withthe image plane are related by a planar projective transformation.Image points x1 and x2 correspond to the same scene point X.
3CG 2006 21 / 1
Relationship in terms of rotationsFor corresponding points x1 and x2 in two views 1 and 2,
x1P=
1 0 0 00 1 0 00 0 1 0
[ R1 00> 1
]XYZ1
= R1
XYZ
x2P= R2
XYZ
Hence
x2 = R2R−11 x1
The cameras could have different focal lengths — so one can do all ofthis while rotating and zooming. Then
x1P= K 1R1
(XYZ
)x2
P= K 2R2
(XYZ
)⇒ x2 = K 2R2R−1
1 K−11 x1
where in the simplest case
K 1 =
f1 0 00 f1 00 0 1
3CG 2006 22 / 1
♣ 2: MosaicsInput sequence: 30 frames, hand held camcorder
3CG 2006 23 / 1
♣ 2: Mosaics
Eight images (out of 30) acquired by rotating a camcorder about itsoptical centre.
Register all the images to one reference image by projectivetransformations.
3CG 2006 24 / 1
♣ 2: Keble Panoramic Mosaic
3CG 2006 25 / 1
♣ 3: Synthetic Rotations
Original image Warped: floor tile square Warped: door squareThe synthetic images are produced by projectively warping theoriginal image so that four corners of an imaged rectangle mapto the corners of a rectangle.Both warpings correspond to a synthetic rotation of the cameraabout the (fixed) camera centre.
3CG 2006 26 / 1
♣ 4: Projective pointing devices: modern DürerHere the rotation joint of apan-tilt camera become theprojection centre, and trackingpeople in the ground planeproduces a track on a notionalfrontal plane — like Durer’smarks. These frontal planetracks are then converted inCartesian tracks viewed fromabove.
3CG 2006 27 / 1
Video Example
Camera tracking by motion nulling Recovered ground plane map
3CG 2006 28 / 1
Summary
We have looked at four classes of transformation (in 2D):
Euclidean: 3 DOF
r11 r12 txr21 r22 ty0 0 1
Similarity: 4 DOF
sr11 sr12 txsr21 sr22 ty0 0 1
Affine: 6 DOF
a11 a12 txa21 a22 ty0 0 1
Projective: 8 DOF
h11 h12 h13h21 h22 h23h31 h32 h33
and have developed their 3D counterparts.