# docsaidlab/mrzscanner architecture

> Architecture diagram of the GitHub repository docsaidlab/mrzscanner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/docsaidlab/mrzscanner
- Repository: https://github.com/docsaidlab/mrzscanner

## Overview

MRZScanner is a Python library for locating and reading machine-readable zones in travel-document images. Its main workflow accepts an image, selects a spotting, detection, recognition, or two-stage mode, and returns MRZ text and, where applicable, a polygon; optional cropping and text postprocessing are handled by the scanner. The repository also contains synthetic detection-data generation and MIDV2020 fine-tuning/benchmark datasets. Edges reflect the sampled scanner and inference calls, plus documented usage; training execution and some dataset workflows are not shown in the excerpts.

Main entry points: [`mrzscanner/scanner.py`](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/scanner.py) (MRZScanner), [`mrzscanner/rec/infer.py`](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/rec/infer.py) (Recognition inference), [`mrzscanner/spotting/infer.py`](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/spotting/infer.py) (Spotting inference), [`mrzscanner/det/infer.py`](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/det/infer.py) (Detection inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Scanner API"]
  node_scanner["MRZScanner<br/>[scanner.py]"]
  node_postprocess["MRZ correction<br/>[scanner.py]"]
end

subgraph group_inference["Model Inference"]
  node_spotting["Spotting inference<br/>[infer.py]"]
  node_detection["Detection inference<br/>[infer.py]"]
  node_recognition["Recognition inference<br/>[infer.py]"]
  node_onnx["ONNX runtime"]
end

subgraph group_decoding["Text Decoding"]
  node_decoder["Text decoder<br/>[utils.py]"]
end

subgraph group_data["Dataset Preparation"]
  node_synthetic_data["Synthetic MRZ data<br/>[train_dataset.py]"]
  node_finetune_data["Fine-tuning data"]
end

node_user(("Image caller"))
node_model_host["Model hosting"]
node_wordcanvas["MRZ generator"]
node_backgrounds[("Background images")]

node_user -->|"submits image"| node_scanner
node_scanner -->|"runs spotting"| node_spotting
node_scanner -->|"runs detection"| node_detection
node_scanner -->|"runs recognition"| node_recognition
node_scanner -->|"gets polygon"| node_detection
node_scanner -->|"passes warped image"| node_recognition
node_scanner -->|"optionally corrects"| node_postprocess
node_spotting -->|"runs model"| node_onnx
node_detection -->|"runs model"| node_onnx
node_recognition -->|"runs model"| node_onnx
node_spotting -->|"decodes output"| node_decoder
node_recognition -->|"decodes output"| node_decoder
node_spotting -->|"downloads missing model"| node_model_host
node_detection -->|"downloads missing model"| node_model_host
node_recognition -->|"downloads missing model"| node_model_host
node_synthetic_data -->|"generates MRZ"| node_wordcanvas
node_synthetic_data -->|"reads backgrounds"| node_backgrounds

click node_scanner "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/scanner.py"
click node_postprocess "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/scanner.py"
click node_spotting "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/spotting/infer.py"
click node_detection "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/det/infer.py"
click node_recognition "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/rec/infer.py"
click node_decoder "https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/utils.py"
click node_synthetic_data "https://github.com/docsaidlab/mrzscanner/blob/main/dataset/train_dataset.py"
click node_finetune_data "https://github.com/docsaidlab/mrzscanner/blob/main/dataset/finetune_dataset.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_scanner,node_postprocess toneBlue
class node_spotting,node_detection,node_recognition,node_onnx,node_backgrounds toneAmber
class node_decoder toneMint
class node_synthetic_data,node_finetune_data toneRose
class node_user,node_model_host,node_wordcanvas toneIndigo
```

## Components

### Scanner API

- [MRZScanner](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/scanner.py): `mrzscanner/scanner.py`
- [MRZ correction](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/scanner.py): `mrzscanner/scanner.py`

### Model Inference

- [Spotting inference](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/spotting/infer.py): `mrzscanner/spotting/infer.py`
- [Detection inference](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/det/infer.py): `mrzscanner/det/infer.py`
- [Recognition inference](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/rec/infer.py): `mrzscanner/rec/infer.py`
- **ONNX runtime**

### Text Decoding

- [Text decoder](https://github.com/docsaidlab/mrzscanner/blob/main/mrzscanner/utils.py): `mrzscanner/utils.py`

### Dataset Preparation

- [Synthetic MRZ data](https://github.com/docsaidlab/mrzscanner/blob/main/dataset/train_dataset.py): `dataset/train_dataset.py`
- [Fine-tuning data](https://github.com/docsaidlab/mrzscanner/blob/main/dataset/finetune_dataset.py): `dataset/finetune_dataset.py`

### Other components

- **Image caller**
- **Model hosting**
- **MRZ generator**
- **Background images**

## Connections

- Image caller → MRZScanner: submits image (evidence: `README.md`)
- MRZScanner → Spotting inference: runs spotting (evidence: `mrzscanner/scanner.py`)
- MRZScanner → Detection inference: runs detection (evidence: `mrzscanner/scanner.py`)
- MRZScanner → Recognition inference: runs recognition (evidence: `mrzscanner/scanner.py`)
- MRZScanner → Detection inference: gets polygon (evidence: `mrzscanner/scanner.py`)
- MRZScanner → Recognition inference: passes warped image (evidence: `mrzscanner/scanner.py`)
- MRZScanner → MRZ correction: optionally corrects (evidence: `mrzscanner/scanner.py`)
- Spotting inference → ONNX runtime: runs model (evidence: `mrzscanner/spotting/infer.py`)
- Detection inference → ONNX runtime: runs model (evidence: `mrzscanner/det/infer.py`)
- Recognition inference → ONNX runtime: runs model (evidence: `mrzscanner/rec/infer.py`)
- Spotting inference → Text decoder: decodes output (evidence: `mrzscanner/spotting/infer.py`)
- Recognition inference → Text decoder: decodes output (evidence: `mrzscanner/rec/infer.py`)
- Spotting inference → Model hosting: downloads missing model (evidence: `mrzscanner/spotting/infer.py`)
- Detection inference → Model hosting: downloads missing model (evidence: `mrzscanner/det/infer.py`)
- Recognition inference → Model hosting: downloads missing model (evidence: `mrzscanner/rec/infer.py`)
- Synthetic MRZ data → MRZ generator: generates MRZ (evidence: `dataset/train_dataset.py`)
- Synthetic MRZ data → Background images: reads backgrounds (evidence: `dataset/train_dataset.py`)
