Blog - APNR — automatic plate recognition from video

How an APNR/ANPR pipeline works: plate localization, matched filters, template OCR, and temporal fusion.

Author
2code
Published
Tags
  • APNR
  • ANPR
  • OpenCV
  • CV

APNR (Automatic Plate Number Recognition, also ANPR) is a classic vision problem: extract a readable license plate from video. Below is a practical Qt + OpenCV-style pipeline: localize → OCR → fuse over time.

Why video instead of a single frame?

One frame is often blurry, angled, or reflective. Across a sequence we can:

  1. find plate candidates on many frames,
  2. recognize characters with varying confidence,
  3. merge results over time (best character wins).

That is what a detectedframe / detectedplate layer does: match by location and frame index, then update characters by score.

Pipeline

Plate localization

A typical path:

  • Sobel (aperture, X/YX/Y order, threshold) — boosts character edges,
  • a matched filter tuned to plate geometry (bright band, darker sides),
  • rectangle selection by area and aspect ratio w/hw/h.

The matched-filter row profile can be written as side Gaussians plus a center lobe:

k(x)={Ae(xt1)2/(0.2σ2)xsideBe(xm)2/(2σ2)xcenterk(x) = \begin{cases} A\, e^{-(x-t_1)^2 / (0.2\sigma^2)} & x \in \text{side} \\[4pt] B\, e^{-(x-m)^2 / (2\sigma^2)} & x \in \text{center} \end{cases}

After correlation, bands with plate-like proportions stand out.

OCR: templates, not deep learning

Characters are compared against bitmap patterns (0–9, A–Z) via image matching. A Polish-plate detail: alphabet subsets:

  • district/region characters (often 2–3 letters) — a different set (incl. B, D, I, O, Z),
  • vehicle-distinctive characters — digits + letters without confusing variants.

Each character stores (ci,si)(c_i, s_i) — glyph and score. Plate confidence:

p=1ni=1nsip = \frac{1}{n}\sum_{i=1}^{n} s_i

Temporal fusion

When the same plate reappears (ROI overlap + small Δt\Delta t):

  • update the bounding box,
  • on character conflicts keep the higher sis_i,
  • maintain the “divider” (space after the region code), typically after the 2nd or 3rd character.

A one-frame OCR glitch no longer ruins the read.

Production takeaways

  1. APNR ≠ OCR alone — localization and tracking are harder than reading a glyph.
  2. Domain rules matter — region codes, length 7–8, alphabet constraints lift precision.
  3. Time is a feature — cross-frame fusion is the cheapest ensemble.

Back to blog

Let's talk about your project