cs 4495 computer vision - cc.gatech.edu

56
Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick Aaron Bobick School of Interactive Computing CS 4495 Computer Vision N-Views (1) – Homographies and Projection

Upload: others

Post on 15-Nov-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Aaron Bobick School of Interactive Computing

CS 4495 Computer Vision N-Views (1) – Homographies and Projection

Page 2: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Administrivia • PS 2:

• Get SDD and Normalized Correlation working for a given windows size – say 5x5. Then try on a few window sizes.

• If too slow, resize the images (imresize) and get your code working. Then try on full images (which are reduced already!).

• Results not perfect on even test images? Should they be? • Yes you can use normxcorr2 (it did say this!) • Some loops are OK. For SSD you might have 3 nested loops (row,

col, disp) but shouldn’t be looping over pixels.

• Now: Multiple-views • FP 7.1, 8 (all)

• Today: First half of 2-Views …

Page 3: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Two views…and two lectures • Projective transforms from image to image

• Some more projective geometry • Points and lines and planes

• Two arbitrary views of the same scene • Calibrated – “Essential Matrix” • Two uncalibrated cameras “Fundamental Matrix”

• Gives epipolar lines

Page 4: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

2D Transformations

Page 5: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

2D Transformations

tx

ty = +

Example: translation

Page 6: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

2D Transformations

tx

ty = + 1

= 1 0 tx

0 1 ty .

Example: translation

Page 7: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

2D Transformations

tx

ty = + 1

= 1 0 tx

0 1 ty .

= 1 0 tx

0 1 ty

0 0 1

.

Example: translation

[ BTW: Now we can chain transformations ]

Homogenous vector

Page 8: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Projective Transformations • Projective transformations: for 2D images it’s a 3x3 matrix

applied to homogenous coordinates

=

wyx

ihgfedcba

wyx

'''

Page 9: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Special Projective Transformations • Translation

• Preserves: • Lengths/Areas • Angles • Orientation • Lines

' 1 0' 0 1

1 0 0 1 1

x

y

x t xy t y

=

R R

Page 10: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Special Projective Transformations • Euclidean (Rigid body)

• Preserves: • Lengths/Areas • Angles • Lines

' cos( ) sin( )' sin( ) cos( )

1 0 0 1 1

x

y

x t xy t y

θ θθ θ

− =

R

Page 11: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Special Projective Transformations • Similarity (trans, rot, scale) transform

• Preserves: • Ratios of Areas • Angles • Lines

' cos( ) sin( )' sin( ) cos( )

1 0 0 1 1

x

y

x a a t xy a a t y

θ θθ θ

− =

R

Page 12: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Special Projective Transformations • Affine transform

• Preserves: • Parallel lines • Ratio of Areas • Lines

''

1 0 0 1 1

x a b c xy d e f y

=

R

Page 13: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Projective Transformations • Remember, these are homogeneous coordinates

' '' '

1 0 0 1

x sx a b c xy sy d e f y

s s

=

Page 14: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Projective Transformations • General projective transform (or Homography)

• Preserves: • Lines

• Also cross ratios

(maybe later)

R

' '' '

1 '

x x a b c xy y d e f y

w g h i w

=

Page 15: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

The projective plane • What is the geometric intuition of using homogenous

coordinates ? • a point in the image is a ray in projective space

• Each point (x,y) on the plane (at z=1) is represented by a ray (sx,sy,s)

– all points on the ray are equivalent: (x, y, 1) ≅ (sx, sy, s)

(0,0,0)

(sx,sy,s)

image plane

(x,y,1)

-y

x -z

Page 16: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image reprojection • Basic question

• How to relate two images from the same camera center? • how to map a pixel from projective plane PP1 to PP2

PP2

PP1

Answer • Cast a ray through each pixel in PP1 • Draw the pixel where that ray

intersects PP2 Observation: Rather than thinking of this as a 3D reprojection, think of it as a 2D image warp from one image to another.

Source: Alyosha Efros

The irrelevant world!

Page 17: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image from http://graphics.cs.cmu.edu/courses/15-463/2010_fall/

Application: Simple mosaics

Page 18: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

How to stitch together a panorama (a.k.a. mosaic)?

• Basic Procedure • Take a sequence of images from the same position

• Rotate the camera about its optical center • Compute transformation between second image and first • Transform the second image to overlap with the first • Blend the two together to create a mosaic • (If there are more images, repeat)

• …but wait, why should this work at all? • What about the 3D geometry of the scene? • Why aren’t we using it?

Source: Steve Seitz

Page 19: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

mosaic PP

Image reprojection

• The mosaic has a natural interpretation in 3D • The images are reprojected onto a common plane • The mosaic is formed on this plane

Warning: This model only holds for

angular views up to 180°. Beyond that

need to use sequence that “bends the

rays” or map onto a different surface, say,

a cylinder.

Page 20: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Mosaics

Obtain a wider angle view by combining multiple images all of which are taken from the same camera center.

. . .

Page 21: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image reprojection: Homography • A projective transform is a mapping between any two PPs

with the same center of projection • rectangle should map to arbitrary quadrilateral • parallel lines aren’t • but must preserve straight lines

• called Homography

PP2

PP1

=

1yx

*********

wwy'wx'

H p p’

Source: Alyosha Efros

Page 22: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homography

( )11, yx ( )11, yx ′′

To compute the homography given pairs of corresponding points in the images, we need to set up an equation where the parameters of H are the unknowns…

( )22 , yx ′′( )22 , yx

( )nn yx , ( )nn yx ′′ ,

Page 23: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

• Can set scale factor i=1. So, there are 8 unknowns. • Set up a system of linear equations Ah = b • where vector of unknowns h = [a,b,c,d,e,f,g,h]T • Need at least 4 points for 8 eqs, but the more the better… • Solve for h. If overconstrained, solve using least-squares:

• Look familiar? (If don’t set i to 1 can use SVD) • >> help mldivide

Solving for homographies

2min -Ah b

=

1yx

ihgfedcba

wwy'wx'

p’ = Hp

Page 24: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homography

=

1yx

*********

wwy'wx'

H p p’

′′

wyw

wxw

,

( )yx ′′= ,

( )yx,

To apply a given homography H • Compute p’ = Hp (regular matrix multiply) • Convert p’ from homogeneous to image

coordinates

Page 25: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Mosaics

Combine images with the computed homographies…

image from

S. Seitz

. . .

Page 26: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Mosaics for Video Coding

• Convert masked images into a background sprite for content-based coding

• + + +

• =

Page 27: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homographies and 3D planes • Remember this:

• Suppose the 3D points are on a plane:

0aX bY cZ d+ + + =

00 01 02 03

10 11 12 13

20 21 22 2311

Xu m m m m

Yv m m m m

Zm m m m

Page 28: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homographies and 3D planes • On the plane [a b c d] can replace Z:

• So, can put the Z coefficients into the others:

00 01 02 03

10 11 12 13

20 21 22 23

( ) / ( )1

1

Xu m m m m

Yv m m m m

aX bY d cm m m m

+ + −

00 01 03

10 11 13

20 21 23

00

( ) / ( )1 0

1

Xu m m m

Yv m m m

aX bY d cm m m

′ ′ ′ ′ ′ ′ + + −

′ ′ ′

3x3 Homography!

Page 29: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image reprojection

• Mapping between planes is a homography. Whether a plane in the world to the image or between image planes.

Page 30: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

What else: Rectifying Slanted Views of Planes

Page 31: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Rectifying slanted views

Corrected image (front-to-parallel)

Page 32: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Measuring distances

Page 33: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

1 2 3 4

1

2

3

4

Measurements on planes

Approach: unwarp then measure What kind of warp is this? Homography…

Page 34: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image rectification

p p’

A planar rectangular grid in the scene. Map it into a rectangular grid in the image.

Page 35: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Some other images of rectangular grids…

Page 36: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Who needs a blimp?

Page 37: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Same pixels – via a homography

Page 38: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Page 39: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Image warping

Given a coordinate transform and a source image f(x,y), how do we compute a transformed image g(x’,y’) = f(T(x,y))?

x x’

T(x,y)

f(x,y) g(x’,y’)

y y’

Slide from Alyosha Efros, CMU

Page 40: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

f(x,y) g(x’,y’)

Forward warping

• Send each pixel f(x,y) to its corresponding location • (x’,y’) = T(x,y) in the second image

x x’

T(x,y)

Q: what if pixel lands “between” two pixels?

y y’

Slide from Alyosha Efros, CMU

Page 41: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

f(x,y) g(x’,y’)

Forward warping

• Send each pixel f(x,y) to its corresponding location • (x’,y’) = T(x,y) in the second image

x x’

T(x,y)

Q: what if pixel lands “between” two pixels?

y y’

A: distribute color among neighboring pixels (x’,y’) – Known as “splatting”

Slide from Alyosha Efros, CMU

Page 42: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

f(x,y) g(x’,y’) x y

Inverse warping

Get each pixel g(x’,y’) from its corresponding location (x,y) = T-1(x’,y’) in the first image

x x’

Q: what if pixel comes from “between” two pixels?

y’ T-1(x,y)

Slide from Alyosha Efros, CMU

Page 43: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

f(x,y) g(x’,y’) x y

Inverse warping

Get each pixel g(x’,y’) from its corresponding location (x,y) = T-1(x’,y’) in the first image

x x’

T-1(x,y)

Q: what if pixel comes from “between” two pixels?

y’

A: Interpolate color value from neighbors – nearest neighbor, bilinear…

Slide from Alyosha Efros, CMU >> help interp2

Page 44: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Bilinear interpolation Sampling at f(x,y):

Slide from Alyosha Efros, CMU

Page 45: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Recap: How to stitch together a panorama (a.k.a. mosaic)? • Basic Procedure

• Take a sequence of images from the same position • Rotate the camera about its optical center

• Compute transformation (homography) between second image and first using corresponding points.

• Transform the second image to overlap with the first. • Blend the two together to create a mosaic. • (If there are more images, repeat)

Source: Steve Seitz

Page 46: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Why projective geometry?

Page 47: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

The projective plane • What is the geometric intuition of using homogenous

coordinates ? • a point in the image is a ray in projective space

• Each point (x,y) on the plane is represented by a ray (sx,sy,s)

– all points on the ray are equivalent: (x, y, 1) ≅ (sx, sy, s)

(0,0,0)

(sx,sy,s)

image plane

(x,y,1)

-y

x -z

Page 48: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homogeneous coordinates 2D Points:

xp

y

=

'1

xp y

=

'' '

'

xp y

w

=

'/ ''/ '

x wp

y w

=

2D Lines:

[ ] 01

xa b c y

=

0ax by c+ + =

[ ] x yl a b c n n d = ⇒

d (nx, ny)

Page 49: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Projective lines • What does a line in the image correspond to in

projective space?

• A line is a plane of rays through origin – all rays (x,y,z) satisfying: ax + by + cz = 0

[ ]

=

zyx

cba0 :notationvectorin

• A line is also represented as a homogeneous 3-vector l l p

l

Page 50: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

l

Point and line duality • A line l is a homogeneous 3-vector • It is ⊥ to every point (ray) p on the line: lTp=0

p1 p2

What is the intersection of two lines l1 and l2 ? • p is ⊥ to l1 and l2 ⇒ p = l1 × l2

Points and lines are dual in projective space • given any formula, can switch the meanings of points and

lines to get another formula

l1

l2

p

What is the line l spanned by rays p1 and p2 ? • l is ⊥ to p1 and p2 ⇒ l = p1 × p2 • l is the plane normal

Page 51: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homogeneous coordinates Line joining two points:

ax + by + c = 0

p1

p1 = x1 y1 1[ ]

p2 = x2 y2 1[ ]

l = p1 × p2

p2

Page 52: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Homogeneous coordinates Intersection between two lines:

a1x + b1y + c1 = 0

a2x + b2y + c2 = 0

x12

l1 = a1 b1 c1[ ]

l2 = a2 b2 c2[ ]

x12 = l1 × l2

Page 53: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

Ideal points and lines

• Ideal point (“point at infinity”) • p ≅ (x, y, 0) – parallel to image plane • It has infinite image coordinates

(sx,sy,0) -y

x -z image plane

Ideal line • l ≅ (a, b, 0) – normal is parallel to (is in!) image plane

(a,b,0) -y

x -z image plane

• Corresponds to a line in the image (finite coordinates) – goes through image origin (principle point)

Page 54: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

3D projective geometry • These concepts generalize naturally to 3D • Recall the equation of a plane:

• Homogeneous coordinates • Projective 3D points have four coords: p = (wX,wY,wZ,w)

• Duality • A plane N is also represented by a 4-vector N =(a,b,c,d) • Points and planes are dual in 3D: NTp = 0

• Projective transformations • Represented by 4x4 matrices T: P’ = TP

0aX bY cZ d+ + + =

Page 55: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

3D to 2D: “perspective” projection

• Matrix Projection: ΠPp =

=

=

1************

ZYX

wwywx

You’ve already seen this. What is not preserved under perspective projection?

What IS preserved?

Page 56: CS 4495 Computer Vision - cc.gatech.edu

Two Views Part 1: 2D transforms and Projective Geometry CS 4495 Computer Vision – A. Bobick

What’s next… • Today – more projective geometry, the duality between

points and lines in projective space

• Tuesday– using the projective geometry revisit 2-views: • Essential and Fundamental matrices