Edd's Knowledge Base

Optical flow is the apparent motion of brightness patterns between two video frames. It is stored as a vector at each pixel, saying how far that pixel’s pattern moved horizontally and vertically. Motion is a powerful visual cue, and sometimes the only one: a handful of moving dots is enough for a person to see a walking body.

Flow can come from camera motion, object motion, or changes of lighting. It is not always the same as true motion: a uniform sphere spinning in place has real motion but produces no flow, and a moving light over a still scene produces flow with nothing moving.

The Three Assumptions

AssumptionMeaning
Brightness constancyThe projection of the same scene point looks the same in every frame
Small motionPoints do not move far between frames (about a pixel or less)
Spatial coherenceA pixel moves like its neighbours

The Brightness Constancy Equation

A point at in frame moves by and appears at in frame with the same brightness:

For small motion, a first-order Taylor expansion of the left side gives

  • are the spatial gradients (Image Gradients and the Sobel Operator).
  • is the temporal derivative: the difference between the two frames.
  • The unknowns are and . In vector form, .

The Aperture Problem

At one pixel this is one equation with two unknowns, so the motion cannot be recovered uniquely. If satisfies it, so does for any perpendicular to the gradient.

  • The component of motion along the gradient (across the edge) is recoverable.
  • The component perpendicular to the gradient (along the edge) is invisible.

Looking through a small window (an aperture) at a straight edge, you can only see motion perpendicular to it. The barber pole illusion is the classic demonstration: the stripes actually rotate around the pole, but you perceive them climbing upward because the motion across the stripes is the only part you can see.

Example: at a pixel with , , (a vertical edge), the equation is , so . Nothing at all is known about .

Lucas-Kanade: More Equations From a Window

Spatial coherence supplies extra equations. Assume all pixels in a window share the same . A window gives 25 equations in the same 2 unknowns:

The system is overdetermined, so solve it by least squares (Least-Squares Line Fitting): , so , with

flowchart LR
    A["Two frames"] --> B["Ix, Iy, It"]
    B --> C["Window sums: A^T A and A^T b"]
    C --> D["Solve 2x2 system for (u, v)"]
    D --> E["Flow vector per pixel"]

Why it works at corners and fails at flat regions

is the same matrix as the structure tensor of the Harris Corner Detector. Its eigenvalues decide whether the flow is well determined:

RegionEigenvalues of Flow estimate
Flatboth smallNone: the system is nearly singular
Edgeone large, one smallOnly the component across the edge (the aperture problem again)
Cornerboth large and similarReliable full

Flow is well estimated exactly where “cornerness” is high, which is why corners are the standard good features to track.

When Lucas-Kanade Fails

FailureFix
Large motion (more than about a pixel) breaks the Taylor expansionCoarse-to-fine estimation on an image pyramid, with iterative refinement (Image Pyramids)
A point does not move like its neighbours (motion boundaries)Motion segmentation: separate layers of coherent motion
Brightness constancy fails (lighting change, specular highlights)Feature matching such as SIFT, or tracking

Smoothness is needed in both space (neighbours move alike) and time (small motion between frames).

Uses

Video stabilization, object and action tracking, traffic and surveillance analysis, motion capture, autonomous driving, and the front end of visual SLAM and augmented reality.

Sources: Lucas and Kanade, An Iterative Image Registration Technique with an Application to Stereo Vision, 1981; Lucas-Kanade method (Wikipedia); Barber pole illusion (Wikipedia).


Related: Computer Vision MOC, Harris Corner Detector, Image Pyramids, Least-Squares Line Fitting, Feature Matching