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.

Install

Please install tesseract before installing the package,

On macOS,

brew install tesseract

On Ubuntu,

sudo apt-get install -y tesseract-ocr

Latest release on PyPI:

$ 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.1.tar.gz (10.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readmrz-0.0.1-py3-none-any.whl (10.9 MB view details)

Uploaded Python 3

File details

Details for the file readmrz-0.0.1.tar.gz.

File metadata

  • Download URL: readmrz-0.0.1.tar.gz
  • Upload date:
  • Size: 10.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.1

File hashes

Hashes for readmrz-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0489cb03ddd1aa4362b88fb622d960fac3f7ed71baf7854f168332bfc59ff6fa
MD5 ca4a3fc7c4411c06292d81033ce4f0b0
BLAKE2b-256 e1885267bbcaea574bd4827606f05c2685f7385302c03dc9a89343fb0244d560

See more details on using hashes here.

File details

Details for the file readmrz-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: readmrz-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.1

File hashes

Hashes for readmrz-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc667271a9410339b659f612abe4941f402ed222b6ac7dbc1790a12074b36a36
MD5 ab39445ef760c4fdb096ad08fe5599c2
BLAKE2b-256 394c29f7c577558c63ffeabd466bf20991c37c99b51a53ba332da4e6617770b1

See more details on using hashes here.

Supported by

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