Machine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.
Project description
Python MRZ Scanner SDK
This project provides a Python-C++ binding for the Dynamsoft Label Recognizer v2.x, allowing developers to build MRZ (Machine Readable Zone) scanner applications on both Windows and Linux platforms using Python.
License Key
To activate the SDK, obtain a 30-day FREE trial license.
Supported Python Versions
- Python 3.x
Installation
Install the required dependencies:
pip install mrz opencv-python
Command-line Usage
-
Scan MRZ from an image file:
scanmrz <file-name> -l <license-key>
-
Scan MRZ from a webcam:
scanmrz <file-name> -u 1 -l <license-key>
Quick Start
import mrzscanner
from mrz.checker.td1 import TD1CodeChecker
from mrz.checker.td2 import TD2CodeChecker
from mrz.checker.td3 import TD3CodeChecker
from mrz.checker.mrva import MRVACodeChecker
from mrz.checker.mrvb import MRVBCodeChecker
def check(lines):
try:
td1_check = TD1CodeChecker(lines)
if bool(td1_check):
return "TD1", td1_check.fields()
except Exception as err:
pass
try:
td2_check = TD2CodeChecker(lines)
if bool(td2_check):
return "TD2", td2_check.fields()
except Exception as err:
pass
try:
td3_check = TD3CodeChecker(lines)
if bool(td3_check):
return "TD3", td3_check.fields()
except Exception as err:
pass
try:
mrva_check = MRVACodeChecker(lines)
if bool(mrva_check):
return "MRVA", mrva_check.fields()
except Exception as err:
pass
try:
mrvb_check = MRVBCodeChecker(lines)
if bool(mrvb_check):
return "MRVB", mrvb_check.fields()
except Exception as err:
pass
return 'No valid MRZ information found'
# set license
mrzscanner.initLicense("LICENSE-KEY")
# initialize mrz scanner
scanner = mrzscanner.createInstance()
# load MRZ model
scanner.loadModel(mrzscanner.load_settings())
print('')
# decodeFile()
s = ""
results = scanner.decodeFile("images/1.png")
for result in results:
print(result.text)
s += result.text + '\n'
print('')
print(check(s[:-1]))
print('')
API Reference
-
mrzscanner.initLicense('YOUR-LICENSE-KEY')
: Initialize the SDK with your license key.mrzscanner.initLicense("LICENSE-KEY")
-
mrzscanner.createInstance()
: Create an instance of the MRZ scanner.scanner = mrzscanner.createInstance()
-
scanner.loadModel(<model configuration file>)
: Load the MRZ model configuration.scanner.loadModel(mrzscanner.load_settings())
-
decodeFile(<image file>)
: Recognize MRZ from an image file.results = scanner.decodeFile(<image-file>) for result in results: print(result.text)
-
decodeMat(<opencv mat data>)
: Recognize MRZ from an OpenCV Mat.import cv2 image = cv2.imread(<image-file>) results = scanner.decodeMat(image) for result in results: print(result.text)
-
addAsyncListener(callback function)
: Register a callback function to receive MRZ recognition results asynchronously. -
decodeMatAsync(<opencv mat data>)
: Recognize MRZ from OpenCV Mat asynchronously.def callback(results): s = "" for result in results: print(result.text) s += result.text + '\n' print('') print(check(s[:-1])) import cv2 image = cv2.imread(<image-file>) scanner.addAsyncListener(callback) for i in range (2): scanner.decodeMatAsync(image) sleep(1)
How to Build the Python MRZ Scanner Extension
-
Create a source distribution:
python setup.py sdist
-
setuptools:
python setup.py build python setup.py develop
-
Build wheel:
pip wheel . --verbose # Or python setup.py bdist_wheel
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 Distribution
File details
Details for the file mrz-scanner-sdk-1.1.1.tar.gz
.
File metadata
- Download URL: mrz-scanner-sdk-1.1.1.tar.gz
- Upload date:
- Size: 21.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7026132e2b3bf11f66f1461fe1b0e8c62fa4489fd587e3d0c53b53cd48b7f7cb |
|
MD5 | 43866c6bdad993a38d0b3a841983fc77 |
|
BLAKE2b-256 | 9b1029d2300193df45fc2adeab9c2712b5e300289dde8b60b7d9c4b107e03511 |
File details
Details for the file mrz_scanner_sdk-1.1.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: mrz_scanner_sdk-1.1.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da0d0cad0b29a246844ef212c6924405653018aa5811a4f0a4107cabb43ad08c |
|
MD5 | e4d1461e5d41c50ea47c4e00c750c7cd |
|
BLAKE2b-256 | 204ca54c980bbaad2c27d982ad795e844dfae79e30088f59c384bd1e96775d82 |