KLT Tracker

The Kanade-Lucas-Tomasi (KLT) tracker follows sparse feature points from frame to frame by directly aligning small image patches, instead of re-detecting and re-matching descriptors every frame. It combines the Lucas-Kanade optical flow solution (Lucas & Kanade, 1981), Tomasi & Kanade’s tracking formulation (1991), and Shi & Tomasi’s feature selection criterion (1994), and — in its pyramidal form (Bouguet) — is the front-end of many VIO systems (MSCKF implementations, VINS-Mono) and the workhorse behind cv::calcOpticalFlowPyrLK.

The Lucas-Kanade core

Assume brightness constancy: the patch around a feature keeps its intensity as it moves by (u,v)(u, v) between frames,

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

For small motion, first-order Taylor expansion gives the optical flow constraint equation:

Ixu+Iyv+It=0I_x u + I_y v + I_t = 0

where Ix,IyI_x, I_y are spatial image gradients and ItI_t is the temporal difference. One equation, two unknowns — the aperture problem. Lucas-Kanade adds spatial coherence: all NN pixels in a window WW around the feature share the same (u,v)(u, v). Stacking the NN constraints and solving by least squares yields the 2×22 \times 2 system

ATA[uv]=ATb,ATA=[Ix2IxIyIxIyIy2]A^T A \begin{bmatrix} u \\ v \end{bmatrix} = -A^T \mathbf{b}, \qquad A^T A = \begin{bmatrix} \sum I_x^2 & \sum I_x I_y \\ \sum I_x I_y & \sum I_y^2 \end{bmatrix}

with b\mathbf{b} the vector of temporal gradients. Because the motion is not truly infinitesimal, this solve is iterated in Gauss-Newton fashion: warp the patch by the current estimate, recompute residuals, solve for an increment, repeat until the update falls below a threshold.

Good features to track

The matrix ATAA^T A is exactly the structure tensor from the Harris corner detector, and its conditioning decides trackability. With eigenvalues λ1λ2\lambda_1 \ge \lambda_2:

Shi & Tomasi’s criterion selects features where min(λ1,λ2)>τ\min(\lambda_1, \lambda_2) > \tau — “good features to track” are, by construction, the points where the KLT solve is stable. This is cv::goodFeaturesToTrack.

Making it work over real motion

Why it matters for SLAM

KLT is the cheap, high-precision alternative to descriptor matching for frame-to-frame correspondence: no descriptor computation, no NN search, sub-pixel accuracy, and computation proportional to the number of tracked points — ideal for the tracking thread of a real-time system on embedded hardware. This is why optical-flow front-ends dominate VIO (VINS-Mono tracks KLT corners and never computes descriptors during normal operation) and why semi-direct methods like SVO are built on the same patch-alignment mathematics. Its limits define front-end design, too: KLT degrades under large baselines, illumination change (brightness constancy breaks), and motion blur, and provides no means to re-find a lost feature — which is exactly what descriptor-based matching and place recognition are for. The KLT normal equations are also the simplest instance of the Gauss-Newton pattern that reappears at every scale of SLAM, up to full photometric bundle adjustment.

Hands-on