MRZ reading

MRZ text filling validity is determined in accordance with ICAO 9303 for machine readable documents. Unlike document reading, it doesn’t not require a previous detection of the document.

MRZ reading module provide functions to read the MRZ as the full string, and to decode its field as a dictionary name:value.

Fields names by MRZ Types

TD2, TD3, MRVA & B

TD1

French ID

Driving License

primary_name

✔️

✔️

✔️

secondary_name

✔️

✔️

✔️

type

✔️

✔️

✔️

issuing_state

✔️

✔️

✔️

document_number

✔️

✔️

✔️

nationality

✔️

✔️

birth_date

✔️

✔️

✔️

gender

✔️

✔️

✔️

expiry_date

✔️

✔️

personal_number

✔️

optional_1

✔️

optional_2

✔️

check_digit_1

✔️

✔️

✔️

check_digit_2

✔️

✔️

✔️

check_digit_3

✔️

✔️

✔️

check_digit_4

✔️

✔️

check_digit_5

✔️

issuing_department

✔️

issuing_office

✔️

issuing_department_2

✔️

issuing_date

✔️

Example

The example below demonstrates how to read, check and decode an MRZ from an image.

# load the deep learning model
id3document.DocumentLibrary.load_model(ai_models_path, id3document.DocumentModel.MRZ_READER_2A, id3document.ProcessingUnit.CPU)

# initialize the MRZ reader
mrz_reader = id3document.MrzReader(
    thread_count=4
)

# load an image from a file.
image = id3document.DocumentImage.from_file(filename, id3document.PixelFormat.BGR_24_BITS)

# read the MRZ
mrz_result = mrz_reader.read_mrz(image)

print(f"Confidence : {mrz_result.confidence}")
print(f"Value      : {mrz_result.mrz}")
print(f"Type       : {mrz_result.mrz_type.name}")

# check the validity of the MRZ
mrz_valid = id3document.MrzHelper.check(mrz_result.mrz, mrz_result.mrz_type)

# decode the MRZ
mrz_fields = id3document.MrzHelper.decode(mrz_result.mrz, mrz_result.mrz_type)

for field in mrz_fields:
    print(f"- {field} = {mrz_fields[field]}")

See also