Top Banner
CAP5415-Computer Vision Lecture 7-Optical Flow Ulas Bagci [email protected] Lecture 7: Optical Flow 1
69

Lecture 7-Optical Flow

Jan 24, 2023

Download

Documents

Khang Minh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 7-Optical Flow

CAP5415-ComputerVisionLecture7-OpticalFlow

[email protected]

Lecture7:OpticalFlow

1

Page 2: Lecture 7-Optical Flow

Readings• Szeliski,R.Ch.7• Bergenetal.ECCV92,pp.237-252.• Shi,J.andTomasi,C.CVPR94,pp.593-600.• Baker,S.andMatthews,I.IJCV2004,pp.221-255.

• SlideCredits:Szeliski andShah.• NewYorkTimes• VideofromMichaelBlack

2

Lecture7:OpticalFlow

Page 3: Lecture 7-Optical Flow

Seeingthevisibleintheinvisible

3

Lecture7:OpticalFlow

Page 4: Lecture 7-Optical Flow

Motion

4

Lecture7:OpticalFlow

U-zu-maki Glasses=>U:rabbits,zu:figure,maki:rotation

Page 5: Lecture 7-Optical Flow

Reasons?

• thepatternsonlymovewhenyoublinkormoveyoureyes

• thearrangementofthebackgroundsofthe‘rabbits’determineswhichwaythepatternsrotate.

5

Lecture7:OpticalFlow

Page 6: Lecture 7-Optical Flow

MotionPerceptionofchangeintheoutsideworldisofthehighestimportanceforalllivingbeings.

Agreatmajorityofchanges insensoryexcitationintheimageresultfrommotion.

Imagesalsochangeverymarkedlywhenalightsourceisturnedonoroff-butthischangecannotbeinterpretedasmotion.

6

Lecture7:OpticalFlow

Page 7: Lecture 7-Optical Flow

WhyEstimateVisualMotion?

• VisualMotioncanbeduetoproblems– Camerainstabilities,jitter

7

Lecture7:OpticalFlow

Page 8: Lecture 7-Optical Flow

WhyEstimateVisualMotion?

• VisualMotioncanbeduetoproblems– Camerainstabilities,jitter

• VisualMotion Indicatesdynamicsinthescene–Movingobjects,behavior,trackingobjects,analyzetrajectories

8

Lecture7:OpticalFlow

Page 9: Lecture 7-Optical Flow

WhyEstimateVisualMotion?

• VisualMotioncanbeduetoproblems– Camerainstabilities,jitter

• VisualMotion Indicatesdynamicsinthescene–Movingobjects,behavior,trackingobjects,analyzetrajectories

• VisualMotionrevealsspatiallayout–Motionparallax

9

Lecture7:OpticalFlow

Page 10: Lecture 7-Optical Flow

Today’sLecture

VisualMotionEstimation• Patch-basedmotion– OpticalFlow

• Lucas-Kanade• Horn-Schunck

• MotionModels

10

Lecture7:OpticalFlow

Page 11: Lecture 7-Optical Flow

Applications

11

Lecture7:OpticalFlow

Motionbasedsegmentation

Structurefrommotion

Alignment(e.g.,UAVanalysis)

VideoCompression

TumorTracking

DeformationAnalysis

Page 12: Lecture 7-Optical Flow

Nature News-Vol 525,Issue7567

12

Lecture7:OpticalFlow

• CVToolsthattrackhowanimalsmovearehelpingresearcherstodoeverythingfromdiagnosingneurologicalconditionstoilluminatingevolution

Higher-speedcameraseventuallyimprovedwhatcouldbecaptured.Butmovementstudiesstillneededapersontolookthroughtheresultsframebyframe,laboriouslytracingthearcofeachstep,armswingorwingflaptoextractinformationaboutanglesandforces.

Page 13: Lecture 7-Optical Flow

13

Lecture7:OpticalFlow

Page 14: Lecture 7-Optical Flow

PerceptionofMotion

14

Lecture7:OpticalFlow

Page 15: Lecture 7-Optical Flow

Video

• Avideoisasequenceofframescapturedovertime– Imagedataisafunctionofspace(x,y)andtime(t)

15

Lecture7:OpticalFlow

I(x,y,t)

tTemporalchange

Page 16: Lecture 7-Optical Flow

ApparentMotion

16

Lecture7:OpticalFlow

Presentdotsonthreemovieframes Seeonemovingdot

Page 17: Lecture 7-Optical Flow

DescribingMotion

17

Lecture7:OpticalFlow

Page 18: Lecture 7-Optical Flow

DescribingMotion• Simplestway:ImageDifferencing(intensityvalues)

18

Lecture7:OpticalFlow

Page 19: Lecture 7-Optical Flow

DescribingMotion• Simplestway:ImageDifferencing(intensityvalues)

19

Lecture7:OpticalFlow

t

t+1

Page 20: Lecture 7-Optical Flow

OpticalFlow

• Referstotheproblemofestimatingavectorfieldoflocaldisplacementinasequenceofimages.

20

Lecture7:OpticalFlow

Page 21: Lecture 7-Optical Flow

OpticalFlow

• Referstotheproblemofestimatingavectorfieldoflocaldisplacementinasequenceofimages.

• Whenwefixourattentiontoasinglepointandmeasurevelocitiesflowingthroughthatlocation,thentheproblemiscalledopticalflow.

21

Lecture7:OpticalFlow

Page 22: Lecture 7-Optical Flow

OpticalFlow

• Referstotheproblemofestimatingavectorfieldoflocaldisplacementinasequenceofimages.

• Whenwefixourattentiontoasinglepointandmeasurevelocitiesflowingthroughthatlocation,thentheproblemiscalledopticalflow.– Stereomatching,imagematching,tracking,…

22

Lecture7:OpticalFlow

Page 23: Lecture 7-Optical Flow

EstimatingOpticalFlow

23

Lecture7:OpticalFlow

• Assumetheimageintensityisconstant

( )tyxI ,, ( )dttdyydxxI +++ ,,=

I

Time=t Time=t+dt

Page 24: Lecture 7-Optical Flow

EstimatingOpticalFlow

24

Lecture7:OpticalFlow

( )tyxI ,, ( )dttdyydxxI +++ ,, !

Page 25: Lecture 7-Optical Flow

EstimatingOpticalFlow

25

Lecture7:OpticalFlow

( )tyxI ,, ( )dttdyydxxI +++ ,, !I(x(t) + u.�t, y(t) + v.�t)� I(x(t), y(t), t) ⇡ 0

Page 26: Lecture 7-Optical Flow

EstimatingOpticalFlow

26

Lecture7:OpticalFlow

( )tyxI ,, ( )dttdyydxxI +++ ,, !I(x(t) + u.�t, y(t) + v.�t)� I(x(t), y(t), t) ⇡ 0

AssumingIisdifferentiablefunction,andexpandthefirsttermusingTaylor’sseries:

@I

@x

dx

dt

+@I

@y

dy

dt

+@I

@t

= 0

Page 27: Lecture 7-Optical Flow

EstimatingOpticalFlow

27

Lecture7:OpticalFlow

( )tyxI ,, ( )dttdyydxxI +++ ,, !I(x(t) + u.�t, y(t) + v.�t)� I(x(t), y(t), t) ⇡ 0

AssumingIisdifferentiablefunction,andexpandthefirsttermusingTaylor’sseries:

@I

@x

dx

dt

+@I

@y

dy

dt

+@I

@t

= 0

Ix

u+ Iy

v + It

= 0Compactrepresentation

Brightnessconstancyconstraint

Page 28: Lecture 7-Optical Flow

Assumption:TheBrightnessConstraint

• Expressestheideaofsimilarbrightnessforthesameobjectsobservedinasequence

28

Lecture7:OpticalFlow

Page 29: Lecture 7-Optical Flow

Assumption:TheBrightnessConstraint

• Expressestheideaofsimilarbrightnessforthesameobjectsobservedinasequence

• Whenwefollowwithagivenlocationandtracetheirpositioninconsecutiveimagesofasequence,thentheproblemiscalled“featuretracking”

29

Lecture7:OpticalFlow

Page 30: Lecture 7-Optical Flow

Assumption:TheBrightnessConstraint

• Expressestheideaofsimilarbrightnessforthesameobjectsobservedinasequence

• Whenwefollowwithagivenlocationandtracetheirpositioninconsecutiveimagesofasequence,thentheproblemiscalled“featuretracking”

• Tryingtosolveasingleequationfortwovariables(uandv)àill-posed

30

Lecture7:OpticalFlow

Ix

u+ Iy

v + It

= 0 ApertureProblem

Page 31: Lecture 7-Optical Flow

ApertureProblem

• Howcertain arethemotionestimates?

31

Lecture7:OpticalFlow

Page 32: Lecture 7-Optical Flow

SecondAssumption:GradientConstraint

32

Lecture7:OpticalFlow

Velocityvectorisconstantwithinasmallneighborhood(LUCASANDKANADE)

Page 33: Lecture 7-Optical Flow

SecondAssumption:GradientConstraint

33

Lecture7:OpticalFlow

Velocityvectorisconstantwithinasmallneighborhood(LUCASANDKANADE)

E(u, v) =

Z

x,y

(Ix

u+ I

y

v + I

t

)2dxdy

Page 34: Lecture 7-Optical Flow

SecondAssumption:GradientConstraint

34

Lecture7:OpticalFlow

Velocityvectorisconstantwithinasmallneighborhood(LUCASANDKANADE)

E(u, v) =

Z

x,y

(Ix

u+ I

y

v + I

t

)2dxdy

@E(u, v)

@u=

@E(u, v)

@v= 0

Page 35: Lecture 7-Optical Flow

SecondAssumption:GradientConstraint

35

Lecture7:OpticalFlow

Velocityvectorisconstantwithinasmallneighborhood(LUCASANDKANADE)

E(u, v) =

Z

x,y

(Ix

u+ I

y

v + I

t

)2dxdy

@E(u, v)

@u=

@E(u, v)

@v= 0

2(Ix

u+ Iy

v + It

)Ix

= 0

2(Ix

u+ Iy

v + It

)Iy

= 0

Page 36: Lecture 7-Optical Flow

Lucas-Kanade

36

Lecture7:OpticalFlow

PI2x

PIx

IyP

Ix

Iy

PI2y

� uv

�= �

PIx

ItP

Iy

It

Page 37: Lecture 7-Optical Flow

Lucas-Kanade

37

Lecture7:OpticalFlow

PI2x

PIx

IyP

Ix

Iy

PI2y

� uv

�= �

PIx

ItP

Iy

It

Txx

Txy

Txy

Tyy

� uv

�= �

Txt

Tyt

�StructuralTensorrepresentation

Page 38: Lecture 7-Optical Flow

Lucas-Kanade

38

Lecture7:OpticalFlow

PI2x

PIx

IyP

Ix

Iy

PI2y

� uv

�= �

PIx

ItP

Iy

It

Txx

Txy

Txy

Tyy

� uv

�= �

Txt

Tyt

�StructuralTensorrepresentation

u =Tyt

Txy

� Txt

Tyy

Txx

Tyy

� T 2xy

and v =Txt

Txy

� Tyt

Txx

Txx

Tyy

� T 2xy

Page 39: Lecture 7-Optical Flow

39

Lecture7:OpticalFlow

Page 40: Lecture 7-Optical Flow

HowdoesLucas-Kanade behave?

40

Lecture7:OpticalFlow

Texturedregion

Txx

Txy

Txy

Tyy

� uv

�= �

Txt

Tyt

Homog.region

EigenvaluesofmatrixTarehigh Eigenvaluesof

matrixTareverysmall

Atedges,matrixTbecomessingular!

Page 41: Lecture 7-Optical Flow

Pitfalls&Alternatives

• Brightnessconstancyisnotsatisfied– Correlation basedmethodcouldbeused

41

Lecture7:OpticalFlow

Page 42: Lecture 7-Optical Flow

Pitfalls&Alternatives

• Brightnessconstancyisnotsatisfied– Correlation basedmethodcouldbeused

• Apointmaynotmovelikeitsneighbors– Regularization basedmethods

42

Lecture7:OpticalFlow

Page 43: Lecture 7-Optical Flow

Pitfalls&Alternatives

• Brightnessconstancyisnotsatisfied– Correlation basedmethodcouldbeused

• Apointmaynotmovelikeitsneighbors– Regularization basedmethods

• Themotionmaynotbesmall(Taylordoesnothold!)–Multi-scaleestimationcouldbeused

43

Lecture7:OpticalFlow

Page 44: Lecture 7-Optical Flow

Multi-ScaleFlowEstimation

44

Lecture7:OpticalFlow

imageIt-1 imageI

GaussianpyramidofimageIt GaussianpyramidofimageIt+1

imageIt+1imageItu=10pixels

u=5pixels

u=2.5pixels

u=1.25pixels

Page 45: Lecture 7-Optical Flow

Example:OpticalFlowin1D

45

Lecture7:OpticalFlow

v! ?

x

),( txI )1,( +txI

p

Page 46: Lecture 7-Optical Flow

Example:OpticalFlowin1D

46

Lecture7:OpticalFlow

v!

xI

Spatialderivative

TemporalderivativetI

x

),( txI )1,( +txI

p

tx x

II¶¶

=px

t tII

=¶¶

=x

t

IIv -»

!Assumptions:

• Brightnessconstancy• Smallmotion

Page 47: Lecture 7-Optical Flow

Example:OpticalFlowin1DLecture7:OpticalFlow

47

x

),( txI )1,( +txI

p

xI

tI

Temporalderivativeat2nd iteration

Iteratinghelpsrefiningthevelocityvector

Cankeepthesameestimateforspatialderivative

x

tprevious I

Ivv -¬!!

Convergesinabout5iterations

Page 48: Lecture 7-Optical Flow

Lukas-Kanade withoutPyramid

48

Lecture7:OpticalFlow

Page 49: Lecture 7-Optical Flow

Lukas-Kanade withPyramid

49

Lecture7:OpticalFlow

Page 50: Lecture 7-Optical Flow

Horn&Schunck

• Globalmethodwithsmoothnessconstrainttosolveapertureproblem

50

Lecture7:OpticalFlow

Page 51: Lecture 7-Optical Flow

Horn&Schunck

• Globalmethodwithsmoothnessconstrainttosolveapertureproblem

• Minimizeaglobalenergyfunction

51

Lecture7:OpticalFlow

Page 52: Lecture 7-Optical Flow

Horn&Schunck

• Globalmethodwithsmoothnessconstrainttosolveapertureproblem

• Minimizeaglobalenergyfunction

52

Lecture7:OpticalFlow

E(u, v) =

Z

x,y

[(Ix

u+ I

y

v + I

t

)2 + ↵

2(|ru|2 + |rv|2)]dxdy

Page 53: Lecture 7-Optical Flow

Horn&Schunck

• Globalmethodwithsmoothnessconstrainttosolveapertureproblem

• Minimizeaglobalenergyfunction

• Takepartialderivativesw.r.t.uandv:

53

Lecture7:OpticalFlow

E(u, v) =

Z

x,y

[(Ix

u+ I

y

v + I

t

)2 + ↵

2(|ru|2 + |rv|2)]dxdy

Page 54: Lecture 7-Optical Flow

Horn&Schunck

• Globalmethodwithsmoothnessconstrainttosolveapertureproblem

• Minimizeaglobalenergyfunction

• Takepartialderivativesw.r.t.uandv:

54

Lecture7:OpticalFlow

E(u, v) =

Z

x,y

[(Ix

u+ I

y

v + I

t

)2 + ↵

2(|ru|2 + |rv|2)]dxdy

(Ix

u+ Iy

v + It

)Ix

� ↵2ru = 0

(Ix

u+ Iy

v + It

)Iy

� ↵2rv = 0

Page 55: Lecture 7-Optical Flow

Horn&Schunck

55

Lecture7:OpticalFlow

• Iterative scheme

• Yields high density flow• Fill in missing information in the homogenous regions• More sensitive to noise than local methods

2221

2221

)(

)(

yx

tk

yk

xykk

yx

tk

yk

xxkk

IIIvIuII

vv

IIIvIuII

uu

++

++-=

++

++-=

+

+

a

a

u

v

),( yx II

),( vu),( vu

Page 56: Lecture 7-Optical Flow

OpticalFlowMatlab/C++/PythonCode

• http://people.csail.mit.edu/celiu/OpticalFlow/• http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html

• https://github.com/Itseez/opencv_attic/blob/a6078cc8477ff055427b67048a95547b3efe92a5/opencv/samples/python2/lk_track.py

56

Lecture7:OpticalFlow

Page 57: Lecture 7-Optical Flow

Applications: TargetTracking

57

Lecture7:OpticalFlow

Page 58: Lecture 7-Optical Flow

Applications: ActionRecognition

58

Lecture7:OpticalFlow

yx FF , +-+-yyxx FFFF ,,, blurred +-+-

yyxx FFFF ,,,

Recognitionactionsatadistance,Efros etal.

Page 59: Lecture 7-Optical Flow

Applications:MotionModeling

59

Lecture7:OpticalFlow

Flippingbetweenimage1and2. Estimatedflowfield(hueindicatesorientationandsaturationindicatesmagnitude)

Secondimageiswarped!

SlidecredittoC.Liu

Page 60: Lecture 7-Optical Flow

Applications:MotionSegmentation

60

Lecture7:OpticalFlow

Page 61: Lecture 7-Optical Flow

GlobalMotionModels(Parametric)Allpixelsareconsideredtosummarizeglobalmotion!

• 2DModels– Affine– Quadratic– Planarprojective(homography)

• 3DModels– Inst.Cameramotionmodels– Homography+epipole– Plane+parallalx

61

Lecture7:OpticalFlow

Page 62: Lecture 7-Optical Flow

MotionModels

62

Lecture7:OpticalFlow

Translation

2 unknowns

Affine

6 unknowns

Perspective

8 unknowns

3D rotation

3 unknowns

Page 63: Lecture 7-Optical Flow

Example:AffineMotion

63

Lecture7:OpticalFlow

u(x, y) = a1 + a2x+ a3y

u(x, y) = a4 + a5x+ a6y

Page 64: Lecture 7-Optical Flow

Example:AffineMotion

64

Lecture7:OpticalFlow

u(x, y) = a1 + a2x+ a3y

u(x, y) = a4 + a5x+ a6y

Ix

u+ Iy

v + It

⇡ 0

Page 65: Lecture 7-Optical Flow

Example:AffineMotion

65

Lecture7:OpticalFlow

u(x, y) = a1 + a2x+ a3y

u(x, y) = a4 + a5x+ a6y

I

x

(a1 + a2x+ a3y) + I

y

(a4 + a5x+ a6y) + I

t

⇡ 0

Page 66: Lecture 7-Optical Flow

Example:AffineMotion

66

Lecture7:OpticalFlow

u(x, y) = a1 + a2x+ a3y

u(x, y) = a4 + a5x+ a6y

Eachpixelprovides1linearconstraintin6globalunknowns(a1,..,a6)

I

x

(a1 + a2x+ a3y) + I

y

(a4 + a5x+ a6y) + I

t

⇡ 0

Page 67: Lecture 7-Optical Flow

Example:AffineMotion

67

Lecture7:OpticalFlow

u(x, y) = a1 + a2x+ a3y

u(x, y) = a4 + a5x+ a6y

Eachpixelprovides1linearconstraintin6globalunknowns(a1,..,a6)

Overallpixels,minimizetheleastsquaretofindunknowns!

Err

a1,...,a6 =X

[Ix

(a1 + a2x+ a3y) + I

y

(a4 + a5x+ a6y)]2

I

x

(a1 + a2x+ a3y) + I

y

(a4 + a5x+ a6y) + I

t

⇡ 0

Page 68: Lecture 7-Optical Flow

Other2DMotionModels

• Quadratic

• Projective

68

Lecture7:OpticalFlow

u = q1 + q2x+ q3y + q7x2 + q8xy

u = q4 + q5x+ q6y + q7xy + q8y2

u =h1 + h2x+ h3y

h7 + h8x+ h9y� x

v =h4 + h5x+ h6y

h7 + h8x+ h9y� y

Page 69: Lecture 7-Optical Flow

FlowCap:2DHumanPosefromOpticalFLow

69

Lecture7:OpticalFlow