Machine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.
Project description
Python Extension: MRZ Scanner SDK
The goal of this project is to provide a Python-C++ binding for Dynamsoft Label Recognizer, enabling developers to create MRZ scanner applications for both Windows and Linux platforms using Python.
License Key
Get a 30-day FREE trial license to activate the SDK.
Supported Python Edition
- Python 3.x
Install Dependencies
pip install mrz opencv-python
Command-line Usage
$ scanmrz <file-name> -l <license-key>
# Show the image with OpenCV
$ 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("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
# 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('')
Methods
-
mrzscanner.initLicense('YOUR-LICENSE-KEY')
# set the license globallymrzscanner.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
-
mrzscanner.createInstance()
# create a MRZ scanner instancescanner = mrzscanner.createInstance()
-
scanner.loadModel(<model configuration file>)
# load MRZ modelscanner.loadModel(mrzscanner.load_settings())
-
decodeFile(<image file>)
# recognize MRZ from an image fileresults = scanner.decodeFile(<image-file>) for result in results: print(result.text)
-
decodeMat(<opencv mat data>)
# recognize MRZ from OpenCV Matimport cv2 image = cv2.imread(<image-file>) results = scanner.decodeMat(image) for result in results: print(result.text)
-
addAsyncListener(callback function)
# start a native thread and register a Python function for receiving the MRZ recognition results -
decodeMatAsync(<opencv mat data>)
# recognize MRZ from OpenCV Mat asynchronouslydef 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 Distributions
Hashes for mrz_scanner_sdk-1.1.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2bbee02022b20bbff1edd22d55838fa3827ba70714825a5f4a0b5d23906fae1 |
|
MD5 | b1c8eec4d6470f824feca631a07067d0 |
|
BLAKE2b-256 | dc41eccd1b8ae3cb9397f5694e2033bc519e1cb28a0d71f98328d64ef2a33bc7 |
Hashes for mrz_scanner_sdk-1.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd597c77fe23445bce119a6667cd5cd77672b0c6c5e2a51bb8ebfd4283016072 |
|
MD5 | 5cd4389a5c510e946e1ef4e4671f97cb |
|
BLAKE2b-256 | 8e5831b5247e88519df5976ba678b2e27a7ff55a4c54c9ae78f5f01953daf6be |
Hashes for mrz_scanner_sdk-1.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d09328096a823f04fc7db333dd41f0fc422f85ed33e6fad3b7b167dc5dffcebb |
|
MD5 | 904b3d4dd5fa561aa85954c3e28f2bf6 |
|
BLAKE2b-256 | 5b4e91a2cf9f9174e17d71e9b3a91e1b2071a9b96ee442883169dd7c73d8a872 |
Hashes for mrz_scanner_sdk-1.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c660f5199f3188b41e55ec416fea550b505fd36cf6008727fa6d701d14f5dc8 |
|
MD5 | 302042c46bdccc1478bdc68b7220fc5f |
|
BLAKE2b-256 | 7dcdae922714968f7f85d87b408929c32a68353760135ca4a5805cca50f90278 |
Hashes for mrz_scanner_sdk-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6374ea79cb53ea6901cc78a872b44e2657ee8653c4628075434e1cf08c8c8497 |
|
MD5 | b1df1b41f26cdfb2a99d6e8ef1f6b38b |
|
BLAKE2b-256 | 8bf1442ac86916a4507ed0970211cc187c106b9fa826808352c7a63bca359b26 |