A Python library for reading MRZ data from passport images using Tesseract OCR
Project description
passport_mrz_extractor is a Python library for extracting and validating Machine Readable Zone (MRZ) data from passport images. It uses Tesseract OCR to read MRZ text and validates it using the mrz library.
Features
Extract MRZ data from passport images.
Validate MRZ data fields, including document type, name, nationality, date of birth, and expiry date.
Automatic image processing for better OCR accuracy.
Installation
You can install passport_mrz_extractor using pip:
pip install passport_mrz_extractor
Requirements
Python >= 3.10
Tesseract OCR installed on your system
To install Tesseract:
Ubuntu: sudo apt install tesseract-ocr
MacOS (using Homebrew): brew install tesseract
Windows: Download the installer from https://github.com/UB-Mannheim/tesseract/wiki
Dependencies
This library requires the following Python packages:
pytesseract - For performing OCR on images.
opencv-python - For image processing.
mrz - For MRZ data validation.
Pillow - For handling image files in Python.
Usage
Here’s how to use passport_mrz_extractor to extract MRZ data from a passport image.
### Basic Example
This example demonstrates extracting all available MRZ fields from an image and handling potential errors.
import mrz_reader
# Path to the passport image
image_path = 'path/to/passport_image.jpg'
try:
mrz_data = mrz_reader.read_mrz(image_path)
print("Extracted MRZ Data:")
for key, value in mrz_data.items():
print(f"{key}: {value}")
except ValueError as e:
print(f"Error reading MRZ: {e}")
### Example of Using Specific MRZ Fields
In this example, we extract specific fields such as the country, document number, and birth date, and print them in a formatted output.
import mrz_reader
# Path to the passport image
image_path = 'path/to/passport_image.jpg'
try:
# Extract MRZ data
mrz_data = mrz_reader.read_mrz(image_path)
# Display specific fields
print("Country of Issue:", mrz_data.get("country"))
print("Document Number:", mrz_data.get("document_number"))
print("Name:", mrz_data.get("name"))
print("Surname:", mrz_data.get("surname"))
print("Date of Birth:", mrz_data.get("birth_date"))
print("Expiry Date:", mrz_data.get("expiry_date"))
print("Nationality:", mrz_data.get("nationality"))
print("Sex:", mrz_data.get("sex"))
except ValueError as e:
print(f"Error reading MRZ: {e}")
Contributing
If you’d like to contribute, please fork the repository and use a feature branch. Pull requests are welcome.
Issues
If you encounter any issues, please report them on the GitHub repository:
License
passport_mrz_extractor is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file passport_mrz_extractor-1.0.tar.gz
.
File metadata
- Download URL: passport_mrz_extractor-1.0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b3697d31e64b751ac6abf923ff4511e82d2a431d335101e7b448d1c65317e22 |
|
MD5 | 06c89d40fcac184ff3a952dc8d921aba |
|
BLAKE2b-256 | f9905ff0320cbd592d499eb27700998ecd8923bbd430136e02cc1c5e39c9e5ab |
File details
Details for the file passport_mrz_extractor-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: passport_mrz_extractor-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44afea5e53d97d7e051c23e2393ce5fb896479593a3899df31c05cd5bb4ee6b6 |
|
MD5 | 491999c4c916e7a8849898e333e23ee7 |
|
BLAKE2b-256 | ce2adbf03f56ec0d7dbe963ab7aee0cddd43a5633d73a27ccaa02bbd4881d736 |
File details
Details for the file passport_mrz_extractor-1.0-py3-none-any.whl
.
File metadata
- Download URL: passport_mrz_extractor-1.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c14f9042c5ba69263f3695f96c37e04065a2a53d06b47ebd46deda7cd17f4957 |
|
MD5 | 0232910be68274bc4721884ffae162b6 |
|
BLAKE2b-256 | 8051cdb62fc44db3e1bf03079c39ad944213b9b1cb4a3fa8ed601db5357dc891 |