MRZ code extraction from visa and passport documents using convolutional neural networks

Yichuan Liu, Hailey James, Otkrist Gupta, Dan Raviv · DOI

TL;DR

MRZNet is a lightweight, two-stage convolutional neural network framework designed specifically to detect and extract Machine-Readable Zone (MRZ) data from passport and visa images. By combining a coarse-to-fine localization strategy with a fully convolutional character recognition branch, it achieves a 100% detection rate and a 99.25% character recognition F1-score while remaining efficient enough for CPU deployment.

What Problem Does This Paper Address?

When you upload a photo of your passport or visa to a financial or immigration app, the system typically looks at the bottom of the document to find the Machine-Readable Zone (MRZ)—the two lines of text filled with numbers, letters, and < filler characters. Reading this zone automatically is vital for identity verification and fraud detection.

However, standard Optical Character Recognition (OCR) engines and general scene-text spotters struggle with real-world smartphone photos. These images often feature arbitrary orientations, complex backgrounds, and massive variations in scale. Processing full, high-resolution images directly is too computationally expensive for production, but downsampling the images blurs the text beyond recognition. Furthermore, general text spotters fail to exploit the rigid, predictable structure of MRZ data, which always consists of exactly two lines of 44 characters.

Examples of passport images with varying scales and orientations

Methods

To solve the resolution dilemma, the authors introduce MRZNet, which utilizes a "coarse-to-fine" architecture consisting of two sub-networks: MRZSpotter (coarse) and MRZSpotter (fine).

  1. Coarse Stage: The original high-resolution image is padded and downsampled to $768 \times 768$ pixels. The coarse network processes this low-resolution view to roughly locate the MRZ bounding box and determine its rotation angle.
  2. Standardization: Using the coarse prediction, the system crops, rotates, and standardizes the original high-resolution image so that the MRZ region is perfectly upright, centered, and spans the full width of a new $768 \times 768$ image.
  3. Fine Stage: The fine network processes this standardized, high-clarity crop to refine the bounding box and extract the text.
Fig. 2: Overall structure of MRZNet. MRZSpotter (coarse) roughly locates the MRZ region from a down-sampled image whereas MRZSpotter (fine) refines the localization on the original high resolution image and recognizes the MRZ text.

Architectural Highlights

  • MobileNetV2 Backbone: Chosen specifically to minimize computational costs for CPU-based production environments.
  • Atrous Spatial Pyramid Pooling (ASPP): Stacked at the end of the backbone to expand the network's receptive field, allowing it to capture the "big picture" context needed to spot large text regions without losing resolution.
  • Fully Convolutional Recognition: Instead of using Recurrent Neural Networks (like LSTMs) which are standard for handling arbitrary text lengths, MRZNet uses bilinear sampling to map the text region directly to a fixed $16 \times 352$ grid. This grid is then convolved down to a precise $2 \times 44$ character grid, perfectly matching the physical layout of an MRZ.

Datasets

The model was trained and evaluated across three distinct datasets:

  • Lendbuzz Dataset (Proprietary): 4,820 real-world passport and visa images from 85 countries, capturing real-world imperfections like motion blur, perspective distortion, and varied lighting. It was split into 3,482 training, 723 validation, and 615 testing samples.
  • MIDV-500: A public identity document dataset, from which 3,335 intact MRZ images were used for testing.
  • SyntheticMRZ: A public synthetic dataset containing 17,113 randomly selected images used to benchmark single-frame detection capabilities.

Key Insights and Ideas

  • The Power of Priors: General text spotters treat text recognition as an open-ended sequence-to-sequence problem. MRZNet proves that when your target domain has a rigid structural prior (2 lines, 44 characters), replacing recurrent layers with a fixed-size fully convolutional grid drastically improves accuracy and reduces model size.
  • Resolution Decoupling: Separating the localization task from the recognition task allows the network to use low-resolution data where context matters, and high-resolution data only where fine details matter.
  • Dice Loss Over Cross-Entropy: For the pixel-level score maps, the authors found that adopting Dice Loss significantly outperformed the balanced cross-entropy loss typically used in text detectors like EAST.

Key Results

MRZNet significantly outperformed commercial and open-source alternatives across multiple benchmarks:

  • Lendbuzz Test Set: Achieved a 100% MRZ detection rate and a 99.25% character recognition macro-F1 score. For comparison, the popular open-source tool PassportEye managed only a 26.50% detection rate.
  • MIDV-500 Dataset: Achieved a 73.94% detection rate and an 85.18% character recognition score, outperforming general text spotters like FOTS and CharNet by a wide margin.
  • Efficiency: Because of its MobileNetV2 backbone, the entire MRZNet framework contains only 28.9M parameters (compared to CharNet's 89.2M). It processes an image in just 0.51 seconds on a GPU and 14.82 seconds on a CPU, making it highly practical for real-world deployment.

Limitations and Future Work

While highly effective, the authors note a few areas for improvement:

  • Perspective Warping: The model assumes the text lines are straight. If a passport page is severely bent or warped, causing curved text lines, accuracy drops. Incorporating a geometric "dewarping" module is a key next step.
  • Environmental Degradation: The framework has not yet been rigorously evaluated on documents that are physically damaged or soiled (e.g., stained by ink, water, mud, or smoke).
  • Granularity: Future iterations could explore character-level bounding box detection to further improve robustness against localized noise or obstructions.

Summary updated

BibTeX
@misc{liu2020mrz,
  author = {Yichuan Liu and Hailey James and Otkrist Gupta and Dan Raviv},
  title = {{MRZ code extraction from visa and passport documents using convolutional neural networks}},
  year = {2020},
  eprint = {2009.05489},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2009.05489},
}
Figure