Menu

Correcting MRZ OCR errors with check digits: O vs 0, I vs 1, and when not to guess
πŸ“°

Correcting MRZ OCR errors with check digits: O vs 0, I vs 1, and when not to guess

DEV Community: pythonΒ·Ali AhmedΒ·11 days ago
#hslEopot
#devtopython#devto#dev#digit#digits
Long article (936 words) β€” no AI summary yet.
Reading 0:00
15s threshold

OCR on a passport's machine-readable zone (MRZ) makes predictable mistakes: O ↔ 0 , I ↔ 1 , B ↔ 8 , S ↔ 5 , Z ↔ 2 . Two fixes follow from the MRZ's structure. Fields that can only be digits (dates, check digits) can be mapped back to digits directly. Mixed fields such as the document number can be repaired by trying confusable swaps until the check digit matches . The catch: a check digit is one digit, so a wrong repair also passes one time in ten . The safe rule is to keep a reading that already passes, accept a repair only when exactly one candidate needs the fewest changes, and otherwise ask for a new photo . Tested Python below.

Why are these errors so common?

The MRZ is printed in OCR-B , a font designed to be machine-readable, but phone photos add blur, glare and perspective, and the remaining ambiguity falls on characters with similar shapes. A document number such as L898902C3 mixes letters and digits, so the OCR engine can't use "this position is always a digit" to settle it.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.