Skip to main content

Machine readable zone reader on ID cards

Project description

readmrz

readmrz detects the machine readable zone on ID cards and extracts the text in that zone.

This zone contains the name, surname, date of birth, etc. of the person to whom the identity card was issued. It has universal standards in new generation identity cards and passports.

In conclusion, readmrz is a tool to read mrz code on identity cards and passports.

Install

Please install tesseract before installing the package,

On macOS,

$ brew install tesseract

On Ubuntu,

$ sudo apt-get install -y tesseract-ocr

On Windows,

$ choco install tesseract

Then you can install the latest release,

$ pip install readmrz

Usage

>>> import json
>>> from readmrz import MrzDetector, MrzReader

>>> detector = MrzDetector()
>>> reader = MrzReader()

>>> image = detector.read('/path/to/file')
>>> cropped = detector.crop_area(image)
>>> result = reader.process(cropped)
>>> print(json.dumps(result))
{
    "surname": "STEARNE",
    "name": "JOHN TIMOTHY KELLY",
    "country": "CAN",
    "nationality": "CAN",
    "birth_date": "580702",
    "expiry_date": "240904",
    "sex": "M",
    "document_type": "P",
    "document_number": "GA302922",
    "optional_data": "",
    "birth_date_hash": "0",
    "expiry_date_hash": "3",
    "document_number_hash": "0",
    "final_hash": "2"
}

or using url,

>>> import json
>>> from readmrz import MrzDetector, MrzReader

>>> detector = MrzDetector()
>>> reader = MrzReader()

>>> image = detector.read_from_url('/url/to/image')
>>> cropped = detector.crop_area(image)
>>> result = reader.process(cropped)
>>> print(json.dumps(result))
{
    "surname": "STEARNE",
    "name": "JOHN TIMOTHY KELLY",
    "country": "CAN",
    "nationality": "CAN",
    "birth_date": "580702",
    "expiry_date": "240904",
    "sex": "M",
    "document_type": "P",
    "document_number": "GA302922",
    "optional_data": "",
    "birth_date_hash": "0",
    "expiry_date_hash": "3",
    "document_number_hash": "0",
    "final_hash": "2"
}

The result is returned as a dict so it's easy to access the fields. You can also use command-line,

$ readmrz -f /path/to/file

or using url,

$ readmrz -u /url/to/image

Example

example

Please check to the notebook to see the results step by step.

Contribution

Please check to the pylint and flake8 steps in workflow before contribution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

readmrz-0.0.2.tar.gz (10.9 MB view hashes)

Uploaded Source

Built Distribution

readmrz-0.0.2-py3-none-any.whl (10.9 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page