2025 · in progress
Reading blurred licence plates
A restoration network that makes a blurred, noisy or compressed French licence plate readable again, trained on plates generated by our code and on public European plates, and scored by an off-the-shelf open-source reader that took no part in training. It runs in your browser below.
Context
Started during an internship with the Gendarmerie nationale (Rodez, 2024–25). Rebuilt here on generated plates and public datasets of real European plates; no real plate is shown on this page.
Stack
- PyTorch
- NAFNet
- ONNX Runtime Web
- YOLOv9-t detector
- fast-plate-ocr
Pipeline
- 1Render French plates + real public crops
- 2Simulate camera degradations
- 3Train NAFNet: masked L1 + 0.02 × reading loss
- 4Score with an independent OCR
- 5Export to ONNX, run in the browser
- characters read by an independent OCR on 158 real test plates degraded 16 ways (test set also used to compare about twenty recipes), degraded → restored (95% CI 81.6–85.5)
- 65.8 → 83.6%
- whole plates read exactly, degraded → restored
- 47.2 → 59.9%
- characters read on the sharp originals, before → after: sharp plates are left alone
- 98.5 → 98.4%
About 36 MB, downloaded once: a plate detector, the restoration network and the reader. Everything then runs in your browser. Your photo is never uploaded and nothing is stored.
Works best on French plates. The restored plate is a guess drawn by a network trained on simulated blur: it can invent characters, and it is never evidence.
How it works
French plates in the current AB-123-CD and the older 1234 AB 56 formats are drawn by our code and pasted into real car photos; real plates from public European datasets (Spain, Ukraine, OpenALPR-EU) are added. A simulator degrades them: camera shake, including blur kernels measured on real photos, defocus, low resolution, noise and JPEG compression. NAFNet, a published restoration architecture (Chen et al., 2022) that we reimplemented and trained from random initialisation, learns to undo the damage. Its loss is an L1 distance that ignores characters masked for privacy, plus a reading loss from a small plate reader trained on generated plates and kept frozen (weight 0.02).
Results
reads J62168 · 6 errors
reads J157GV · 2 errors
LJ-757-GV
reads PP723HS · 1 error
reads EP723HS · exact
EP-723-HS
reads 1377F · 3 errors
reads PL137ZF · exact
PL-137-ZF
reads 9340NN86 · 1 error
reads 9320NN86 · exact
9320 NN 86
reads CR177TT · 4 errors
reads CS149OT · 1 error
CS-149-QT
reads FL586PW · exact
reads FL586PW · exact
FL-586-PWThe judge is an off-the-shelf open-source reader we did not train (fast-plate-ocr, European model). On 158 real plates never seen in training (149 from a French public dataset, 9 from OpenALPR), each degraded 16 ways on a frozen bench, restoration raises the characters read from 65.8% to 83.6%: reading errors fall from 34% to 16%. Restoration also invents characters: 3.0% of restored plates are read wrong with high confidence, against 0.7% of degraded inputs, while plates with four or more wrong characters drop from 17.3% to 6.3%. These gains are measured under simulated blur. On a small check with real blur, dashcam video frames of plates in another country’s typeface, the model did not help overall: it redraws letters in the French typeface, D read as O, Y as V. It is meant for French plates. Figures 1 and 3 use plates generated by our code only.
Technical details
Generated plates
The renderer draws French plates at 4 pixels per millimetre on the 520 × 110 mm format of the 9 February 2009 regulation: 75 mm characters, 44 mm wide (25 mm for a 1), 15 × 10 mm dashes, 44 × 98 mm blue bands with twelve five-point stars. It covers the current AB-123-CD format and the older 1234 AB 56 format, white at the front and yellow at the back. The typeface is a free condensed DIN look-alike: the official font is not freely available.
A simulated camera photographs each plate (angle, distance, lighting, glare, dirt, sensor noise, JPEG), and the result is pasted into a real car photo from a public dataset. Real plate crops from UC3M-LP (Spain), AUTO.RIA (mostly Ukraine) and the OpenALPR European benchmark make up the other half of each batch, split by vehicle so that no vehicle appears in two splits.
- Formats
- SIV AB-123-CD, FNI 1234 AB 56 front and rear
- Output
- 520 × 112 RGB
- Real plates
- UC3M-LP, AUTO.RIA, OpenALPR-EU
Degradations
For every training pair the simulator draws a camera: sensor resolution, defocus, camera shake (mostly real blur kernels measured on real photos, otherwise a random walk), exposure and noise, in-camera sharpening or denoising, then one or two JPEG compressions. One defect is strong and the others light, and a few pairs stay nearly clean, so that the network also learns to leave sharp plates alone.
- Defects
- shake, defocus, resolution, noise, compression
Network and loss
NAFNet is a U-shaped restoration network without non-linear activation functions: gating by element-wise products replaces them. Four encoder levels halve the resolution each time, four decoder levels restore it, with skip connections across; the output is added to the input, so the network learns the correction. It is reimplemented from the paper and trained from random initialisation, without pretrained weights.
The pixel loss is an L1 distance that skips the characters hidden for privacy in the public datasets, so the network is never taught to draw a grey box. A small plate reader, trained on generated plates and then frozen, adds a reading loss with weight 0.02: the restored plate should be readable, not only close in pixels.
- Width
- 32 channels at full resolution
- Blocks
- encoder 1, 1, 2, 4 · middle 4 · decoder 1, 1, 1, 1
- Parameters
- 11.6 million
- Loss
- masked L1 + 0.02 × reading loss
Evaluation
The judge is fast-plate-ocr with its European model, an off-the-shelf reader that took no part in training. The test set is 158 real plates never used in training or checkpoint selection (the recipe was compared on it across about twenty runs, a mild optimistic bias), 149 from a French public dataset and 9 from OpenALPR, each degraded 16 ways. The degraded inputs are written to disk once with their hashes, so every model is scored on the same bytes.
Restoration also invents. A reading that is wrong yet confident is the dangerous case: 3.0% of restored plates against 0.7% of degraded inputs. Large failures become rarer: plates with four or more wrong characters fall from 17.3% to 6.3%.
A single reading is not the only output. A beam search over the reader’s per-slot scores lists the most likely whole plates; keeping only strings in a French format (AB-123-CD or 1234 AB 56) and renormalising helps a little more. Over the 2,528 degraded images (2,448 of French-format plates for the filter), the true plate is ranked first / in the top five for 47.2% / 51.1% of degraded inputs, 59.8% / 67.2% of restored plates, and 62.3% / 68.9% with the French filter. The scores shown in the demo are the reader’s own, not calibrated probabilities.
- OCR judge
- fast-plate-ocr, European MobileViT v2 model
- Test
- 158 real plates (149 French, 9 OpenALPR) × 16 degradations
- Characters read
- 65.8% degraded → 83.6% restored (95% CI 81.6–85.5)
- Whole plates exact
- 47.2% → 59.9%
- Sharp originals
- 98.5% → 98.4%
- Confidently wrong
- 0.7% → 3.0%
- 4 or more wrong characters
- 17.3% → 6.3%
- True plate 1st / in top 5, degraded
- 47.2% / 51.1%
- Same, restored
- 59.8% / 67.2%
- Same, restored + French format
- 62.3% / 68.9%
A diffusion refiner
A Brownian-bridge diffusion model, starting from the NAFNet output and running 8 steps, was tried as a refiner. It reads 83.2% of characters, no better, and invents slightly more. It is useful for another reason: drawn four times, when the four samples agree (67% of plates) the reading is exact 83% of the time, against 12% when they disagree. Disagreement between samples flags the uncertain characters.
- Characters read
- 83.2%, against 83.6% for NAFNet alone
- 4 samples agree
- 67% of plates, 83% of them exact
- Samples disagree
- 12% exact
Limits
Every gain above is measured on real plates under simulated degradation: no public set of really blurred French plates with a sharp reference exists. On a small real-blur check, dashcam video frames of plates in another country’s typeface, the model did not help overall. It redraws letters in the French typeface it was trained on, reading D as O and Y as V.
The restored plate is therefore a guess. It can point to candidates on a French plate; it is never evidence.
The browser demo
The demo runs the same network exported to ONNX, with weights stored as 16-bit floats to halve the download (computation stays in 32-bit), and the same reader. The reader’s image preprocessing is reproduced exactly: on ten generated plates the browser code gives the Python judge’s readings and probabilities. The photo is processed on the device and never sent anywhere.
A photo goes through three steps. A plate detector, the YOLOv9 model of open-image-models (MIT code, weights used unchanged), finds the plate. The window given to the network is sized on the width of the box, because detector boxes are about 20% taller than hand-drawn ones and sizing on the height made the plate too small. Five slightly different framings are restored and read, and the reader’s scores are averaged over them. The reading turned out to be very sensitive to framing, and this averaging removes most of that sensitivity.
These choices were made on validation photos, never on the test plates: 274 plates from the Spanish validation set, read exactly after restoration. On blurred photos, a single framing sized like the first version of the demo read 37% of plates with the detector’s box, against 57% with the width-sized five-framing average, and 59% with the hand-drawn box. On sharp photos: 37%, 65% and 68%. The detector finds 94% of validation plates, and blur does not lower that rate. When it misses one, drawing a box by hand works as before.
- Runtime
- ONNX Runtime Web, WebAssembly
- Detector
- YOLOv9-t, 640 × 640, 7.8 MB, finds 94% of validation plates, blurred or not
- Framings
- 5: margins 1.0, 1.08, 1.16 and two side shifts, scores averaged
- Plates read exactly, blurred validation photos
- 37% single framing → 57% five framings (59% with a hand-drawn box)
- Download
- about 36 MB, once