cs 4495 computer vision motion and optic...

59
Motion and Optic Flow CS 4495 Computer Vision – A. Bobick Aaron Bobick School of Interactive Computing CS 4495 Computer Vision Motion and Optic Flow

Upload: others

Post on 16-Feb-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Aaron BobickSchool of Interactive Computing

    CS 4495 Computer VisionMotion and Optic Flow

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Administrivia

    • PS4 is out, due Wed Oct 29th.

    • Details about Problem Set:• You may *not* use built in Harris corner functions.• If using C or Python, you can use the relevant functions in OpenCV• There is a “supplement” document that explains these two systems.• Scale is not explored. • Yes you can use various gradient functions

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Visual motion

    Many slides adapted from S. Seitz, R. Szeliski, M. Pollefeys, K. Grauman and others…

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Video• A video is a sequence of frames captured over time• Now our image data is a function of space

    (x, y) and time (t)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion Applications: Segmentation of video• Background subtraction

    • A static camera is observing a scene• Goal: separate the static background from the moving foreground

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion Applications: Segmentation of video• Background subtraction• Shot boundary detection

    • Commercial video is usually composed of shots or sequences showing the same objects or scene

    • Goal: segment video into shots for summarization and browsing (each shot can be represented by a single keyframe in a user interface)

    • Difference from background subtraction: the camera is not necessarily stationary

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion Applications: Segmentation of video• Background subtraction• Shot boundary detection• Motion segmentation

    • Segment the video into multiple coherently moving objects

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion Applications: Segmentation of video• Background subtraction• Shot boundary detection• Motion segmentation

    • Segment the video into multiple coherently moving objects

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion and perceptual organization

    Gestalt psychology (Max Wertheimer, 1880-1943)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

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

    Gestalt psychology (Max Wertheimer, 1880-1943)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion and perceptual organization

    • Sometimes, motion is the only cue

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion and perceptual organization

    • Sometimes, motion is the only cue

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion and perceptual organization

    • Sometimes, motion is the only cue

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

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

    percept

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

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

    percept

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Mosaicing

    (Michal Irani, Weizmann)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Mosaicing

    (Michal Irani, Weizmann)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    More applications of motion• Segmentation of objects in space or time• Estimating 3D structure• Learning dynamical models – how things move• Recognizing events and activities• Improving video quality (motion stabilization)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion estimation techniques• Feature-based methods

    • Extract visual features (corners, textured areas) and track them over multiple frames

    • Sparse motion fields, but more robust tracking• Suitable when image motion is large (10s of pixels)

    • Direct, dense methods• Directly recover image motion at each pixel from spatio-temporal

    image brightness variations• Dense motion fields, but sensitive to appearance variations• Suitable for video and when image motion is small

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Motion estimation: Optical flow

    Will start by estimating motion of each pixel separatelyThen will consider motion of entire image

    Optic flow is the apparent motion of objects or surfaces

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Problem definition: optical flow

    How to estimate pixel motion from image I(x,y,t) to I(x,y,t+1) ?• Solve pixel correspondence problem

    – given a pixel in I(x,y,t), look for nearby pixels of the same color in I(x,y,t+1)

    Key assumptions• color constancy: a point in I(x,y, looks the same in I(x,y,t+1)

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

    This is called the optical flow problem

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical flow constraints (grayscale images)

    • Let’s look at these constraints more closely• brightness constancy constraint (equation)

    • small motion: (u and v are less than 1 pixel, or smooth) Taylor series expansion of I:

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

    ( , ) ( , ) [higher order terms]I II x u y v I x y u vx y∂ ∂

    + + = + + +∂ ∂

    ( , ) I II x y u vx y∂ ∂

    ≈ + +∂ ∂

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    0 ( , , 1) ( , , )( , , 1) ( , , )x y

    I x u y v t I x y tI x y t I u I v I x y t

    = + + + −≈ + + + −

    Optical flow equation• Combining these two equations

    (Short hand: 𝐼𝐼𝑥𝑥 =𝜕𝜕𝜕𝜕𝜕𝜕𝑥𝑥

    for t or t+1)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    0 ( , , 1) ( , , )( , , 1) ( , , )

    [ ( , , 1) ( , , )]

    ,

    x y

    x y

    t x y

    t

    I x u y v t I x y tI x y t I u I v I x y tI x y t I x y t I u I v

    I I u I vI I u v

    = + + + −≈ + + + −

    ≈ + − + +

    ≈ + +

    ≈ +∇ ⋅ < >

    Optical flow equation• Combining these two equations

    (Short hand: 𝐼𝐼𝑥𝑥 =𝜕𝜕𝜕𝜕𝜕𝜕𝑥𝑥

    for t or t+1)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    0 ( , , 1) ( , , )( , , 1) ( , , )

    [ ( , , 1) ( , , )]

    ,

    x y

    x y

    t x y

    t

    I x u y v t I x y tI x y t I u I v I x y tI x y t I x y t I u I v

    I I u I vI I u v

    = + + + −≈ + + + −

    ≈ + − + +

    ≈ + +

    ≈ +∇ ⋅ < >

    Optical flow equation• Combining these two equations

    In the limit as u and v go to zero, this becomes exact

    Brightness constancy constraint equation0x y tI u I v I+ + =

    0 ,tI I u v= +∇ ⋅ < >

    (Short hand: 𝐼𝐼𝑥𝑥 =𝜕𝜕𝜕𝜕𝜕𝜕𝑥𝑥

    for t or t+1)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical flow equation

    • Q: how many unknowns and equations per pixel?2 unknowns, one equation

    0x y tI u I v I+ + =0 ,tI I u v= +∇ ⋅ < > or

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    (u’,v’)

    Optical flow equation

    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

    edge

    (u,v)gradient

    (u+u’,v+v’)

    0x y tI u I v I+ + =0 ,tI I u v= +∇ ⋅ < > or

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Aperture problem

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Aperture problem

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Aperture problem

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Apparently an aperture problem

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical flow equation

    • Q: how many unknowns and equations per pixel?

    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

    Some folks say: “This explains the Barber Pole illusion”http://www.sandlotscience.com/Ambiguous/Barberpole_Illusion.htmhttp://www.liv.ac.uk/~marcob/Trieste/barberpole.html

    2 unknowns, one equation

    http://en.wikipedia.org/wiki/Barber's_pole

    Not quite… where do the vectors point?

    http://www.sandlotscience.com/Ambiguous/Barberpole_Illusion.htmhttp://www.liv.ac.uk/%7Emarcob/Trieste/barberpole.html

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Smooth Optical Flow (Horn and Schunk - long ago)• Formulate Error in Optical Flow Constraint:

    • We need additional constraints!

    • Smoothness Constraint (as in shape from shading and stereo):

    Usually motion field varies smoothly in the image. So, penalize departure from smoothness:

    • Find (u,v) at each image point that MINIMIZES:

    2( )c x y timage

    e I u I v I dx dy= + +∫∫

    dydxvvuue yxyximage

    s )()(2222 +++= ∫∫

    cs eee λ+= weightingfactor

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Solving the aperture problem• How 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!

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Lukas-Kanade flow• Prob: we have more equations than unknowns

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

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Aperture Problem and Normal Flow

    0

    0

    =•∇

    =++

    UI

    IvIuI tyx

    The gradient constraint:

    Defines a line in the (u,v) space

    u

    v

    Normal Flow:

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Combining Local Constraints

    u

    v 11tIUI −=•∇

    22tIUI −=•∇33tIUI −=•∇

    etc.

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    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)ATA is solvable when there is no aperture problem

    – Does this remind you of something???

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Eigenvectors of ATA

    • Recall the Harris corner detector: M = ATA is the second moment matrix

    • The eigenvectors and eigenvalues of M relate to edge direction and magnitude • The eigenvector associated with the larger eigenvalue points in the

    direction of fastest intensity change• The other eigenvector is orthogonal to it

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Interpreting the eigenvalues

    λ1

    λ2“Corner”λ1 and λ2 are large,λ1 ~ λ2

    λ1 and λ2 are small “Edge” λ1 >> λ2

    “Edge” λ2 >> λ1

    “Flat” region

    Classification of image points using eigenvalues of the second moment matrix:

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Low texture region

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Edge

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    High textured region

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

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    RGB version• How 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!

    Note that RGB alone at pixel is not enough to disambiguate because R, G & B are correlated. Just provides better gradient

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Errors in Lucas-Kanade• A point does not move like its neighbors

    • Motion segmentation

    • Brightness constancy does not hold• Do exhaustive neighborhood search with normalized correlation -

    tracking features – maybe SIFT – more later….

    • The motion is large (larger than a pixel)1. Not-linear: Iterative refinement2. Local minima: coarse-to-fine estimation

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Not tangent: Iterative RefinementIterative Lukas-Kanade Algorithm

    1. Estimate velocity at each pixel by solving Lucas-Kanade equations2. Warp It towards It+1 using the estimated flow field

    • - use image warping techniques3. Repeat until convergence

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Iterative Estimation

    xx0

    Initial guess: Estimate:

    estimate update

    (using d for displacement here instead of u)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Iterative Estimation

    xx0

    estimate update

    Initial guess: Estimate:

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Iterative Estimation

    xx0

    Initial guess: Estimate:Initial guess: Estimate:

    estimate update

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Iterative Estimation

    xx0

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Iterative Estimation• Some Implementation Issues:

    • Warping is not easy (ensure that errors in warping are smaller than the estimate refinement) – but it is in MATLAB!

    • Often useful to low-pass filter the images before motion estimation (for better derivative estimation, and linear approximations to image intensity)

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Revisiting the small motion assumption

    • Is this motion small enough?• Probably not—it’s much larger than one pixel • How might we solve this problem?

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow: Aliasing

    Temporal aliasing causes ambiguities in optical flow because images can have many pixels with the same intensity.I.e., how do we know which ‘correspondence’ is correct?

    nearest match is correct (no aliasing)

    nearest match is incorrect (aliasing)

    To overcome aliasing: coarse-to-fine estimation.

    actual shift

    estimated shift

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Reduce the resolution!

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    image 2image 1

    Gaussian pyramid of image 1 Gaussian pyramid of image 2

    image 2image 1 u=10 pixels

    u=5 pixels

    u=2.5 pixels

    u=1.25 pixels

    Coarse-to-fine optical flow estimation

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    image Iimage J

    Gaussian pyramid of image 1 Gaussian pyramid of image 2

    image 2image 1

    Coarse-to-fine optical flow estimation

    run iterative L-K

    run iterative L-K

    warp & upsample

    .

    .

    .

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow Results

    * From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    Optical Flow Results

    * From Khurram Hassan-Shafique CAP5415 Computer Vision 2003

  • Motion and Optic FlowCS 4495 Computer Vision – A. Bobick

    State-of-the-art optical flowStart with something similar to Lucas-Kanade+ gradient constancy+ energy minimization with smoothing term+ region matching+ keypoint matching (long-range)

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

    Region-based +Pixel-based +Keypoint-based

    http://www.cs.berkeley.edu/%7Ebrox/pub/brox_cvpr09.pdf

    CS 4495 Computer Vision�Motion and Optic FlowAdministriviaVisual motionVideoMotion Applications: Segmentation of videoMotion Applications: Segmentation of videoMotion Applications: Segmentation of videoMotion Applications: Segmentation of videoMotion and perceptual organizationMotion and perceptual organizationMotion and perceptual organizationMotion and perceptual organizationMotion and perceptual organizationMotion and perceptual organizationMotion and perceptual organizationMosaicingMosaicingMore applications of motionMotion estimation techniquesMotion estimation: Optical flowProblem definition: optical flowOptical flow constraints (grayscale images)Optical flow equationOptical flow equationOptical flow equationOptical flow equationOptical flow equationAperture problemAperture problemAperture problemApparently an aperture problemOptical flow equationSmooth Optical Flow (Horn and Schunk - long ago)Solving the aperture problemLukas-Kanade flowAperture Problem and Normal FlowCombining Local ConstraintsConditions for solvabilityEigenvectors of ATAInterpreting the eigenvaluesLow texture regionEdgeHigh textured regionRGB versionErrors in Lucas-KanadeNot tangent: Iterative RefinementOptical Flow: Iterative EstimationOptical Flow: Iterative EstimationOptical Flow: Iterative EstimationOptical Flow: Iterative EstimationOptical Flow: Iterative EstimationRevisiting the small motion assumptionOptical Flow: AliasingReduce the resolution!Coarse-to-fine optical flow estimationCoarse-to-fine optical flow estimationOptical Flow ResultsOptical Flow ResultsState-of-the-art optical flow