Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz,...

56
1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides.

Transcript of Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz,...

Page 1: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

1

Optical Flow-Based Motion Estimation

Thanks to Steve Seitz, Simon Baker, TakeoKanade, and anyone else who helped develop these slides.

Page 2: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

2

Why estimate motion?

We live in a 4-D world

Wide applications• Object Tracking• Camera Stabilization• Image Mosaics• 3D Shape Reconstruction

(SFM)• Special Effects (Match

Move)

Page 3: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

3

Optical flow

Page 4: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

4

Problem definition: optical flow

How to estimate pixel motion from image H to image I?• Solve pixel correspondence problem

– given a pixel in H, look for nearby pixels of the same color in I

Key assumptions• color constancy: a point in H looks the same in I

– For grayscale images, this is brightness constancy• small motion: points do not move very far

This is called the optical flow problem

Page 5: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

5

Optical flow constraints (grayscale images)

Let’s look at these constraints more closely• brightness constancy: Q: what’s the equation?

• small motion: (u and v are less than 1 pixel)– suppose we take the Taylor series expansion of I:

H(x, y) = I(x+u, y+v)

Page 6: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

6

Optical flow equationCombining these two equations

The x-component ofthe gradient vector.

What is It ? The time derivative of the image at (x,y)

How do we calculate it?

Page 7: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

7

Optical flow equation

Q: how many unknowns and equations per pixel?1 equation, but 2 unknowns (u and v)

Intuitively, what does this constraint mean?

• The component of the flow in the gradient direction is determined• The component of the flow parallel to an edge is unknown

Page 8: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

8

Aperture problem

Page 9: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

9

Aperture problem

Page 10: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

10

Solving the aperture problemBasic idea: assume motion field is smooth

Lukas & Kanade: assume locally constant motion• pretend the pixel’s neighbors have the same (u,v)

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

Many other methods exist. Here’s an overview:• Barron, J.L., Fleet, D.J., and Beauchemin, S, Performance of optical flow

techniques, International Journal of Computer Vision, 12(1):43-77, 1994.

Page 11: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

11

Lukas-Kanade flowHow to get more equations for a pixel?

• Basic idea: impose additional constraints– most common is to assume that the flow field is smooth locally– one method: pretend the pixel’s neighbors have the same (u,v)

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

Page 12: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

12

RGB versionHow to get more equations for a pixel?

• Basic idea: impose additional constraints– most common is to assume that the flow field is smooth locally– one method: pretend the pixel’s neighbors have the same (u,v)

» If we use a 5x5 window, that gives us 25*3 equations per pixel!

Page 13: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

13

Lukas-Kanade flowProb: we have more equations than unknowns

Solution: solve least squares problem• minimum least squares solution given by solution (in d) of:

• The summations are over all pixels in the K x K window• This technique was first proposed by Lukas & Kanade (1981)

Page 14: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

14

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

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)

Page 15: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

15

Edges cause problems

– large gradients, all the same– large λ1, small λ2

Page 16: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

16

Low texture regions don’t work

– gradients have small magnitude– small λ1, small λ2

Page 17: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

17

High textured region work best

– gradients are different, large magnitudes– large λ1, large λ2

Page 18: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

18

Errors in Lukas-KanadeWhat are the potential causes of errors in this procedure?

• Suppose ATA is easily invertible• Suppose there is not much noise in the image

When our assumptions are violated• Brightness constancy is not satisfied• The motion is not small• A point does not move like its neighbors

– window size is too large– what is the ideal window size?

Page 19: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

19

Revisiting the small motion assumption

Is this motion small enough?• Probably not—it’s much larger than one pixel (2nd order terms dominate)• How might we solve this problem?

Page 20: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

20

Reduce the resolution!

Page 21: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

21

Coarse-to-fine optical flow estimation

image Iimage H

Gaussian pyramid of image H Gaussian pyramid of image I

image Iimage H u=10 pixels

u=5 pixels

u=2.5 pixels

u=1.25 pixels

Page 22: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

22

Coarse-to-fine optical flow estimation

image Iimage J

Gaussian pyramid of image H Gaussian pyramid of image I

image Iimage H

run iterative L-K

run iterative L-K

warp & upsample

.

.

.

Page 23: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

23

A Few Details• Top Level

• Apply L-K to get a flow field representing the flow from the first frame to the second frame.

• Apply this flow field to warp the first frame toward the second frame.

• Rerun L-K on the new warped image to get a flow field from it to the second frame.

• Repeat till convergence.

• Next Level• Upsample the flow field to the next level as the first guess of

the flow at that level.• Apply this flow field to warp the first frame toward the second

frame.• Rerun L-K and warping till convergence as above.

• Etc.

Page 24: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

24

The Flower Garden Video

What should theoptical flow be?

Page 25: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

25

Robust Visual Motion Analysis: Piecewise-Smooth Optical Flow

Ming YeMing YeElectrical Engineering

University of Washington

Page 26: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

26

Structure From Motion

Rigid scene + camera translation Estimated horizontal motion

Depth map

Page 27: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

27

Scene Dynamics Understanding

Brighter pixels =>largerspeeds.

Estimated horizontal motion• Surveillance• Event analysis• Video compression

Motionboundariesare smooth.

Motion smoothness

Page 28: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

28

Target Detection and Tracking

Tracking resultsA tiny airplane --- only observable by its distinct motion

Page 29: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

29

Problem Statement

Assuming only brightness conservationand piecewise-smooth motion, find the optical flow to best describe the intensity change in three frames.

Page 30: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

30

Approach: Matching-Based Global Optimization

• Step 1. Robust local gradient-based method for high-quality initial flow estimate.

• Step 2. Global gradient-based method to improve theflow-field coherence.

• Step 3. Global matching that minimizes energy by a greedy approach.

Page 31: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

31

Global Energy DesignGlobal energy ∑ +=

s sites all)()( sSsB VEVEE VS is the optical flow field.

EB is the brightness error.ES is the smoothness error.

I is the current frame, and I- and I+ are prev & next frame.I- (Vs) is the warped intensity in prev frame.EB measures the minimum brightness difference between |I-(Vs)-Is| and |I+(Vs)-Is)|

I- I I+

∑∈

−=8

)|,(|81)(

s

sNn

SnsiS VVVE σρES is the flow smoothnesserror in a neighborhoodabout pixel s.

Page 32: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

Overall Algorithm

3210−pV

pIwarp

pwI

pV0

Calculate gradients

ii SBpV σσ ,,0∆

Global matchingpV2

Projection

Level p

Level p-1

Local OFC

pwI∇

Global OFCpV1∆

pV1

Image pyramid

1−PI

pI

0I

Page 33: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

33

Advantages

Best of Everything• Local OFC

– High-quality initial flow estimates– Robust local scale estimates

• Global OFC– Improve flow smoothness

• Global Matching– The optimal formulation– Correct errors caused by poor gradient quality and hierarchical

process

Results: fast convergence, high accuracy, simultaneous motion boundary detection

Page 34: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

34

Experiments

• Experiments were run on several standard test videos.

• Estimates of optical flow were made for the middleframe of every three.

• The results were compared with the Black andAnandan algorithm.

Page 35: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

35

TS: Translating SquaresHomebrew, ideal setting, test performance upper bound

Groundtruth (cropped),Our estimate looks the same

64x64, 1pixel/frame

Page 36: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

36

TS: Flow Estimate Plots

BA S1 (S2 is close)LS

S3 looks the same as the groundtruth.

S1, S2, S3: results from our Step I, II, III (final)

Page 37: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

37

TT: Translating Tree

BAS3

150x150 (Barron 94)

BA 2.60 0.128 0.0724S3 0.248 0.0167 0.00984

)(o∠e )(pix||•e )(pixe

e: error in pixels, cdf: culmulative distribution function for all pixels

Page 38: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

38

DT: Diverging Tree

150x150 (Barron 94)

BAS3

BA 6.36 0.182 0.114S3 2.60 0.0813 0.0507

)(o∠e )(pix||•e )(pixe

Page 39: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

39

YOS: Yosemite Fly-Through

BA 2.71 0.185 0.118S3 1.92 0.120 0.0776

)(o∠e )(pix||•e )(pixeBAS3

316x252 (Barron, cloud excluded)

Page 40: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

40

TAXI: Hamburg Taxi

256x190, (Barron 94)max speed 3.0 pix/frame

LMS BA

Error mapOurs Smoothness error

Page 41: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

41

Traffic

512x512(Nagel)

max speed:6.0 pix/frame

BA

Ours Error map Smoothness error

Page 42: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

42

Pepsi Can

201x201(Black)

Max speed:2pix/frame Ours

SmoothnesserrorBA

Page 43: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

43

FG: Flower Garden

360x240 (Black)Max speed: 7pix/frame

BA LMS

Ours Error map Smoothness error

Page 44: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

44

MPEG Motion Compression

Some frames are encoded in terms of others.

Independent frame encoded as a still image using JPEG

Predicted frame encoded via flow vectors relative to the independent frame and difference image.

Between frame encoded using flow vectors and independent and predicted frame.

Page 45: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

MPEG compression method

45

F1 is independent. F4 is predicted. F2 and F3 are between.

Each block of I is matched to its closest match in P and represented by a motion vector and a block difference image.

Frames B1 and B2 between I and P are represented by twomotion vectors per block referring to blocks in F1 and F4.

Page 46: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

46

Example of compression

Assume frames are 512 x 512 bytes, or 32 x 32 blocks of size 16 x 16 pixels.

Frame A is ¼ megabytes = 250,000 bytes before JPEG

Frame B uses 32 x 32 =1024 motion vectors, or 2048bytes only if delX and delY are represented as 1 byte integers.

Page 47: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

47

Segmenting videos

Build video segment databaseScene change is a change of environment: newsroom

to streetShot change is a change of camera view of same sceneCamera pan and zoom, as beforeFade, dissolve, wipe are used for transitions

Page 48: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

48

Scene change

Page 49: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

49

Detect via histogram change

(Top) gray level histogram of intensities from frame 1 in newsroom.

(Middle) histogram of intensities from frame 2 in newsroom.

(Bottom) histogram of intensities from street scene.

Histograms change less with pan and zoom of same scene.

Page 50: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

50

Daniel Gatica Perez’s work ondescribing video content

Page 51: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

51

Our problem: Finding Video Structure

Video Structure: hierarchical description of visual content Table of Contents

From thousands of raw frames to video events

Page 52: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

52

Hierarchical Structure in Video: Extensive Operators

Shots: Consecutive frames recorded from a single camera

Shot

Clusters: Collection of temporally adjacent/visually similar shots

Cluster

Scenes: Semantic Concept. Fair to use?

Scene

Video Sequence

Sequence

Frame

Page 53: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

53

Daniel’s Approach

TEMPORAL PARTITION GENERATION

VIDEO SHOTFEATURE EXTRACTION

PROBABILISTIC HIERARCHICAL CLUSTERING

CONSTRUCTION OFVIDEO SEGMENT TREE

VIDEO SEQUENCE

Page 54: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

54

Video Structuring Results (I)

35 shots9 clusters detected

Page 55: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

55

Video Structuring Results (II)

12 shots 4 clusters

Page 56: Optical Flow-Based Motion Estimation...1 Optical Flow-Based Motion Estimation Thanks to Steve Seitz, Simon Baker, Takeo Kanade, and anyone else who helped develop these slides. 2 Why

56

Tree-based Video Representation