structure from motion, feature tracking, and optical flow computer vision cs 543 / ece 549...

62
Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted from Lana Lazebnik, Silvio Saverse, who in turn adapted slides from Steve Seitz, Rick Szeliski, Martial Hebert, Mark Pollefeys, and others

Upload: lisa-holmes

Post on 12-Jan-2016

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Structure from Motion, Feature Tracking, and Optical Flow

Computer VisionCS 543 / ECE 549

University of Illinois

Derek Hoiem

04/15/10

Many slides adapted from Lana Lazebnik, Silvio Saverse, who in turn adapted slides from Steve Seitz, Rick Szeliski, Martial Hebert, Mark Pollefeys, and others

Page 2: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Last class

• Estimating 3D points and depth– Triangulation from corresponding points– Dense stereo

• Projective structure from motion

Page 3: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

This class

• Factorization method for structure from motion

• Feature tracking

• Optical flow (dense tracking)

Page 4: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Structure from motion under orthographic projection

3D Reconstruction of a Rotating Ping-Pong Ball

C. Tomasi and T. Kanade. Shape and motion from image streams under orthography: A factorization method. IJCV, 9(2):137-154, November 1992.

•Reasonable choice when •Change in depth of points in scene is much smaller than distance to camera•Cameras do not move towards or away from the scene

Page 5: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Start with an affine camera model

• Affine projection is a linear mapping + translation in inhomogeneous coordinates

x

Xa1

a2

bAXx

2

1

232221

131211

b

b

Z

Y

X

aaa

aaa

y

x

Projection ofworld origin

Does this ever happen?

Page 6: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Get rid of b by shifting to centroid

n

kikijij n 1

1ˆ xxxbAXx

ji

n

kkji

n

kikiiji

n

kikij nnn

XAXXAbXAbXAxx ˆ111

111

jiij XAx ˆˆ 2d normalized point

(observed)

3d normalized point

Linear (affine) mapping

Page 7: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Suppose we know 3D points and affine camera parameters …

then, we can compute the observed 2d positions of each point

mnmm

n

n

n

m xxx

xxx

xxx

XXX

A

A

A

ˆˆˆ

ˆˆˆ

ˆˆˆ

21

22221

11211

212

1

Camera Parameters (2mx3)

3D Points (3xn)

2D Image Points (2mxn)

What rank is the matrix of 2D points?

Page 8: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

What if we instead observe corresponding 2d image points?

Can we recover the camera parameters and 3d points?

cameras (2 m)

points (n)

n

mmnmm

n

n

XXX

A

A

A

xxx

xxx

xxx

D

212

1

21

22221

11211

?

ˆˆˆ

ˆˆˆ

ˆˆˆ

Page 9: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Factorizing the measurement matrix

Source: M. Hebert

AX

Page 10: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Factorizing the measurement matrix

Source: M. Hebert

• Singular value decomposition of D:

Page 11: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Factorizing the measurement matrix

Source: M. Hebert

• Singular value decomposition of D:

Page 12: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Factorizing the measurement matrix

Source: M. Hebert

• Obtaining a factorization from SVD:

Page 13: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Factorizing the measurement matrix

Source: M. Hebert

• Obtaining a factorization from SVD:

A~

X~

Page 14: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Affine ambiguity

• The decomposition is not unique. We get the same D by using any 3×3 matrix C and applying the transformations A → AC, X →C-1X

• That is because we have only an affine transformation and we have not enforced any Euclidean constraints (like forcing the image axes to be perpendicular, for example)

Source: M. Hebert

S~

A~

X~

Page 15: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

• Orthographic: image axes are perpendicular and of unit length

Eliminating the affine ambiguity

x

Xa1

a2

a1 · a2 = 0

|a1|2 = |a2|2 = 1

Source: M. Hebert

Page 16: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Solve for orthographic constraints

• Solve for L = CCT

• Recover C from L by Cholesky decomposition: L = CCT

• Update A and X: A = AC, X = C-1X

Ti

Ti

i

2

1

~

~~

a

aAwhere

1~~11 Ti

TTi aCCa

1~~22 Ti

TTi aCCa

0~~21 Ti

TTi aCCa

~ ~

Three equations for each image i

Page 17: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Algorithm summary• Given: m images and n tracked features xij• For each image i, center the feature coordinates• Construct a 2m × n measurement matrix D:

– Column j contains the projection of point j in all views– Row i contains one coordinate of the projections of all

the n points in image i• Factorize D:

– Compute SVD: D = U W VT

– Create U3 by taking the first 3 columns of U– Create V3 by taking the first 3 columns of V– Create W3 by taking the upper left 3 × 3 block of W

• Create the motion and shape matrices:– M = U3W3

½ and S = W3½ V3

T (or M = U3 and S = W3V3T)

• Eliminate affine ambiguitySource: M. Hebert

Page 18: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Dealing with missing data• So far, we have assumed that all points are

visible in all views• In reality, the measurement matrix typically

looks something like this:

One solution:– solve using a dense submatrix of visible points (as

in last lecture)– Iteratively add new cameras

cameras

points

Page 19: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Reconstruction results

C. Tomasi and T. Kanade. Shape and motion from image streams under orthography: A factorization method. IJCV, 9(2):137-154, November 1992.

Page 20: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Recovering motion• Feature-tracking

– Extract visual features (corners, textured areas) and “track” them over multiple frames

• Optical flow– Recover image motion at each pixel from spatio-temporal image

brightness variations (optical flow)

B. Lucas and T. Kanade. An iterative image registration technique with an application tostereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.

Two problems, one registration method

Page 21: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Feature tracking• Last problem required corresponding points in

images• If motion is small, tracking is an easy way to

get them

Page 22: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Feature tracking

• Challenges– Need good features to track– Points may appear or disappear: need to be able

to add/delete tracked points– Some points may change appearance over time

(e.g., due to rotation, moving into shadows, etc.)– Drift: small errors can accumulate if appearance

model is updated

Page 23: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Feature tracking

• Given two subsequent frames, estimate the point translation

• Key assumptions of Lucas-Kanade Tracker• Brightness constancy: projection of the same point looks the

same in every frame• Small motion: points do not move very far• Spatial coherence: points move like their neighbors

I(x,y,t–1) I(x,y,t)

Page 24: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

tyx IyxvIyxuItyxItvyuxI ),(),()1,,(),,(

• Brightness Constancy Equation:),()1,,( ),,(),( tyxyx vyuxItyxI

Linearizing right hand side using Taylor expansion:

The brightness constancy constraint

I(x,y,t–1) I(x,y,t)

0 tyx IvIuIHence,

Image derivative along x

0IvuI tT

tyx IyxvIyxuItyxItvyuxI ),(),()1,,(),,(

Page 25: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The brightness constancy constraint

• How many equations and unknowns per pixel?

The component of the motion perpendicular to the gradient (i.e., parallel to the edge) cannot be measured

edge

(u,v)

(u’,v’)

gradient

(u+u’,v+v’)

If (u, v ) satisfies the equation, so does (u+u’, v+v’ ) if

•One equation (this is a scalar equation!), two unknowns (u,v)

0IvuI tT

0'v'uI T

Can we use this equation to recover image motion (u,v) at each pixel?

Page 26: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The aperture problem

Actual motion

Page 27: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The aperture problem

Perceived motion

Page 28: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The barber pole illusion

http://en.wikipedia.org/wiki/Barberpole_illusion

Page 29: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The barber pole illusion

http://en.wikipedia.org/wiki/Barberpole_illusion

Page 30: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Solving the ambiguity…

• How to get more equations for a pixel?• Spatial coherence constraint • Assume the pixel’s neighbors have the same (u,v)

– If we use a 5x5 window, that gives us 25 equations per pixel

B. Lucas and T. Kanade. An iterative image registration technique with an application to stereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.

Page 31: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

• Least squares problem:

Solving the ambiguity…

Page 32: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Matching patches across images• Overconstrained linear system

The summations are over all pixels in the K x K window

Least squares solution for d given by

Page 33: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Conditions for solvability– Optimal (u, v) satisfies Lucas-Kanade equation

Does this remind you of anything?

When is This Solvable?• ATA should be invertible • ATA should not be too small due to noise

– eigenvalues 1 and 2 of ATA should not be too small• ATA should be well-conditioned

– 1/ 2 should not be too large ( 1 = larger eigenvalue)

Criteria for Harris corner detector

Page 34: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Edge

– gradients very large or very small– large1, small 2

Page 35: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Low-texture region

– gradients have small magnitude

– small1, small 2

Page 36: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

High-texture region

– gradients are different, large magnitudes

– large1, large 2

Page 37: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The aperture problem resolved

Actual motion

Page 38: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

The aperture problem resolved

Perceived motion

Page 39: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Dealing with larger movements: Iterative refinement

1. Initialize (u,v) = (0,0)2. Compute (u,v) by

3. Shift window by (u, v)4. Repeat steps 2-3 until small change

• Only It changes per iteration

2nd moment matrix for feature patch in first image displacement

It = I(x, y, t-1) - I(x+u, y+v, t)

Page 40: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

image Iimage J

Gaussian pyramid of image 1 (t) Gaussian pyramid of image 2 (t+1)

image 2image 1

Dealing with larger movements: coarse-to-fine registration

run iterative L-K

run iterative L-K

upsample

.

.

.

Page 41: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Shi-Tomasi feature tracker

• Find good features using eigenvalues of second-moment matrix– Key idea: “good” features to track are the ones whose

motion can be estimated reliably• From frame to frame, track with Lucas-Kanade

– This amounts to assuming a translation model for frame-to-frame feature movement

• Check consistency of tracks by affine registration to the first observed instance of the feature– Affine model is more accurate for larger displacements– Comparing to the first frame helps to minimize drift

J. Shi and C. Tomasi. Good Features to Track. CVPR 1994.

Page 42: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Tracking example

J. Shi and C. Tomasi. Good Features to Track. CVPR 1994.

Page 43: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Summary of KLT tracking• Find a good point to track (harris corner)• Use intensity second moment matrix and

difference across frames to find displacement• Iterate and use coarse-to-fine search to deal

with larger movements• When creating long tracks, check appearance

of registered patch against appearance of initial patch to find points that have drifted

Page 44: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Picture courtesy of Selim Temizer - Learning and Intelligent Systems (LIS) Group, MIT

Optical flow

Vector field function of the spatio-temporal image brightness variations

Page 45: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Motion and perceptual organization• Sometimes, motion is the only cue

Page 46: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Motion and perceptual organization• Even “impoverished” motion data can evoke a

strong percept

G. Johansson, “Visual Perception of Biological Motion and a Model For Its Analysis", Perception and Psychophysics 14, 201-211, 1973.

Page 47: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Motion and perceptual organization• Even “impoverished” motion data can evoke a

strong percept

G. Johansson, “Visual Perception of Biological Motion and a Model For Its Analysis", Perception and Psychophysics 14, 201-211, 1973.

Page 48: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Uses of motion• Estimating 3D structure• Segmenting objects based on motion cues• Learning and tracking dynamical models• Recognizing events and activities• Improving video quality (motion

stabilization)

Page 49: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Motion field• The motion field is the projection of the 3D

scene motion into the image

What would the motion field of a non-rotating ball moving towards the camera look like?

Page 50: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Optical flow• Definition: optical flow is the apparent motion

of brightness patterns in the image• Ideally, optical flow would be the same as the

motion field• Have to be careful: apparent motion can be

caused by lighting changes without any actual motion– Think of a uniform rotating sphere under fixed

lighting vs. a stationary sphere under moving illumination

Page 51: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Lucas-Kanade Optical Flow• Same as Lucas-Kanade feature tracking, but

for each pixel– As we saw, works better for textured pixels

• Operations can be done one frame at a time, rather than pixel by pixel– Efficient

Page 52: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

60

Iterative Refinement

• Iterative Lukas-Kanade Algorithm1. Estimate velocity at each pixel by solving Lucas-

Kanade equations

2. Warp I(t-1) towards I(t) using the estimated flow field- use image warping techniques

3. Repeat until convergence

* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 53: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

image Iimage J

Gaussian pyramid of image 1 (t) Gaussian pyramid of image 2 (t+1)

image 2image 1

Coarse-to-fine optical flow estimation

run iterative L-K

run iterative L-K

warp & upsample

.

.

.

Page 54: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Example

* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 55: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Multi-resolution registration

* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 56: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Optical Flow Results

* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 57: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Optical Flow Results

* From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

Page 58: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Errors in Lucas-Kanade• The motion is large

– Possible Fix: Descriptor matching• A point does not move like its neighbors

– Possible Fix: Motion segmentation• Brightness constancy does not hold

– Possible Fix: Gradient constancy

Page 59: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

State-of-the-art optical flow

Start with something similar to Lucas-Kanade+ gradient constancy+ energy minimization with smoothing term+ region matching+ descriptor matching (long-range)

Large displacement optical flow, Brox et al., CVPR 2009

Page 60: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Stereo vs. Optical Flow

• Similar dense matching procedures

• Why don’t we typically use epipolar constraints for optical flow?

B. Lucas and T. Kanade. An iterative image registration technique with an application tostereo vision. In Proceedings of the International Joint Conference on Artificial Intelligence, pp. 674–679, 1981.

Page 61: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Summary• Major contributions from Lucas, Tomasi, Kanade

– Structure from motion– Tracking feature points– Optical flow

• Key ideas– Factorization for special case of SFM– By assuming brightness constancy, truncated Taylor

expansion leads to simple and fast patch matching across frames

– Coarse-to-fine registration

Page 62: Structure from Motion, Feature Tracking, and Optical Flow Computer Vision CS 543 / ECE 549 University of Illinois Derek Hoiem 04/15/10 Many slides adapted

Next class• Kalman filter tracking (with David)