← CS Lab AI & Machine Learning / KLT Tracking Open standalone ↗

KLT tracking follows the same point across video frames by matching a tiny image patch. Its trick is to only bother with points that are actually followable — corners — and then slide their patch into the next frame to see where they went.

Where you meet it

What it does

Two jobs, really. First it decides which points are worth tracking — texture-less regions and plain edges are hopeless. Then, for each good point, it finds its new location in the next frame — without re-searching the whole image, just a small local nudge.

You can only pin a point down in a direction where the patch actually changes — which is exactly why edges slip and corners stick.

How it works

To follow a point, take the little patch around it from frame 1 and slide it over frame 2. At each offset (u,v) measure the SSD — the Sum of Squared Differences of the pixel values. Where the two patches line up best, the SSD is smallest, and that offset is where the point moved.

Now the deep part: think of that SSD as a function of the offset — a bowl. Near the best match the bowl's steepness is captured by a small 2×2 matrix M, the structure tensor, built from the image's gradients over the patch. Its two eigenvalues λ₁ ≥ λ₂ are how steeply the bowl rises along its two main directions:

match:  SSD(u,v) = Σ ( I2(x+u, y+v) − I1(x, y) )²      # Sum of Squared Differences

near the best offset the error is a bowl:  SSD ≈ [u v] · M · [u v]ᵗ
                    Ix²    Ix·Iy          # M = structure tensor
      M = Σ   Ix·Iy   Iy²           #   (Ix, Iy = image gradients over the patch)

score = min(λ₁, λ₂)     # the smaller eigenvalue: how steep the WEAKEST direction is

A flat patch has both eigenvalues near zero — the bowl is flat, nothing to lock onto. An edge has one big, one near zero — the bowl is a long trough, so the patch slides freely along the edge (the aperture problem) and the offset is ambiguous. A corner has both eigenvalues large — a steep bowl in every direction, one sharp minimum, an unambiguous match. That is why the Shi–Tomasi score is min(λ₁, λ₂): a track is only as reliable as its weakest direction, so you demand that even that one curves steeply.

Watch out

  • "SSD" here means Sum of Squared Differences — a patch-matching error. It is not the SSD from deep learning (Single-Shot Detector, an object-detection network). Same three letters, unrelated idea.
  • Never track edges or flat patches. On an edge the match slides along it and the tracked point drifts — the aperture problem. Picking corners (min-eigenvalue) is what avoids this.
  • KLT assumes small motion and constant brightness. The patch is taken to look the same and move only a little between frames; fast motion, lighting changes, or occlusion break the SSD match. Real trackers use an image pyramid to cope with larger jumps.

A corner is just a patch whose error-bowl is steep from every side — so its match has nowhere to slide.

Go deeper

KLT-Tracking verfolgt denselben Punkt über Videoframes, indem es einen winzigen Bildausschnitt matcht. Der Kniff: nur Punkte nehmen, die sich überhaupt verfolgen lassen — Ecken — und ihren Patch in den nächsten Frame schieben, um zu sehen, wohin sie gewandert sind.

Wo es vorkommt

Was es tut

Eigentlich zwei Aufgaben. Zuerst entscheidet es, welche Punkte überhaupt trackbar sind — strukturlose Flächen und glatte Kanten sind aussichtslos. Dann findet es für jeden guten Punkt seine neue Position im nächsten Frame — ohne das ganze Bild neu zu durchsuchen, nur mit einem kleinen lokalen Schubs.

Festnageln kannst du einen Punkt nur in einer Richtung, in der sich der Ausschnitt tatsächlich ändert — genau deshalb rutschen Kanten und halten Ecken.

Wie es funktioniert

Um einen Punkt zu verfolgen, nimmst du den kleinen Ausschnitt um ihn herum aus Frame 1 und schiebst ihn über Frame 2. Bei jedem Versatz (u,v) misst du das SSD — die Sum of Squared Differences (Summe der quadrierten Pixeldifferenzen). Wo beide Ausschnitte am besten übereinstimmen, ist das SSD am kleinsten — und dieser Versatz ist der Weg, den der Punkt genommen hat.

Jetzt der tiefe Teil: Denk dir dieses SSD als Funktion des Versatzes — eine Schüssel. Nahe am besten Match wird ihre Steilheit von einer kleinen 2×2-Matrix M beschrieben, dem Struktur-Tensor, gebaut aus den Bildgradienten über dem Ausschnitt. Seine zwei Eigenwerte λ₁ ≥ λ₂ sagen, wie steil die Schüssel entlang ihrer zwei Hauptrichtungen ansteigt:

Match:  SSD(u,v) = Σ ( I2(x+u, y+v) − I1(x, y) )²      # Sum of Squared Differences

nahe am besten Versatz ist der Fehler eine Schüssel:  SSD ≈ [u v] · M · [u v]ᵗ
                    Ix²    Ix·Iy          # M = Struktur-Tensor
      M = Σ   Ix·Iy   Iy²           #   (Ix, Iy = Bildgradienten über dem Ausschnitt)

score = min(λ₁, λ₂)     # der kleinere Eigenwert: wie steil die SCHWÄCHSTE Richtung ist

Ein flacher Ausschnitt hat beide Eigenwerte nahe null — die Schüssel ist flach, nichts zum Festhalten. Eine Kante hat einen großen, einen fast null — die Schüssel ist eine lange Rinne, der Ausschnitt rutscht frei die Kante entlang (das Aperturproblem) und der Versatz ist mehrdeutig. Eine Ecke hat beide Eigenwerte groß — eine steile Schüssel in jede Richtung, ein scharfes Minimum, ein eindeutiger Match. Darum ist der Shi–Tomasi-Score min(λ₁, λ₂): ein Track ist nur so verlässlich wie seine schwächste Richtung — also verlangst du, dass selbst die steil verläuft.

Worauf achten

  • "SSD" heißt hier Sum of Squared Differences — ein Matching-Fehler. Es ist nicht das SSD aus dem Deep Learning (Single-Shot Detector, ein Objekterkennungs-Netz). Gleiche drei Buchstaben, völlig anderes Konzept.
  • Nie Kanten oder flache Ausschnitte tracken. An einer Kante rutscht der Match entlang und der Punkt driftet — das Aperturproblem. Genau das vermeidet die Ecken-Auswahl über den kleinsten Eigenwert.
  • KLT setzt kleine Bewegung und konstante Helligkeit voraus. Der Ausschnitt soll gleich aussehen und sich nur wenig bewegen; schnelle Bewegung, Lichtwechsel oder Verdeckung brechen den SSD-Match. Echte Tracker nutzen eine Bildpyramide für größere Sprünge.

Eine Ecke ist einfach ein Ausschnitt, dessen Fehler-Schüssel von jeder Seite steil ist — sein Match hat nirgendwohin zu rutschen.

Mehr dazu

Next up
AI & Machine Learningk-Fold Cross-Validation AI & Machine LearningCNN Stride & Padding All concepts →