Document reading

The DocumentReader class extracts data from ID documents. It requires as input an aligned image of a document (see Document detection for details)

Important

The document reader requires the relevant AI models to run.

../_images/cni_aligned.jpg

Aligned image of the ID document, after detection

Important

The document name to pass to the function if the full name, including the potential suffix _front or _back.
It can be retrieved from the detected document DocumentInfo.name Property in the detected document.

Example

The example below demonstrates how to read the French ID card.

# initialize the DocumentReader
DocumentLibrary.load_model(ai_models_path, DocumentModel.OCR_LATIN_2A, ProcessingUnit.CPU)

reader = id3document.DocumentReader(
    thread_count = 4
    )

document_name = "FRA_BO_03001_front" # Retrieved from the detected DocumentInfo

text_fields = reader.read_document(aligned_document_image, document_name, False)

print("Text fields:")
for text_field in text_fields:
    print(f"- {text_field.name} = {text_field.value}")

# Extract photo
photo = reader.extract_face(aligned_document_image, document_name)

See also