Machine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.
Project description
Python Extension: MRZ Scanner SDK
The project is a Python-C++ binding of Dynamsoft Label Recognizer. It aims to help developers build Python MRZ scanner apps on Windows and Linux.
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.get_model_path())
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.get_model_path())
-
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mrz-scanner-sdk-1.0.6.tar.gz.
File metadata
- Download URL: mrz-scanner-sdk-1.0.6.tar.gz
- Upload date:
- Size: 21.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc9081caa49448533f4fe02fc7ea413cf4abda18703230ccb2bca8353d44f3f
|
|
| MD5 |
6fd3efca4bf0e737d04da7415b9c2b61
|
|
| BLAKE2b-256 |
59416c3d43a550e84d5ec93347189f3fbe66aee815e2de0058188c3fc3d6fbce
|
File details
Details for the file mrz_scanner_sdk-1.0.6-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: mrz_scanner_sdk-1.0.6-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/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3edccc16e0194ab7f52be13f6aa4f51835300707f19c6cb1a4c3120e22e475b7
|
|
| MD5 |
e640dbd4c0ca8726ec8c32b5c8ee91ca
|
|
| BLAKE2b-256 |
e2394b8a4cf227fe0dca9be2d7490791ef6368f84fe97a743f7479a42b18a8ad
|
File details
Details for the file mrz_scanner_sdk-1.0.6-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: mrz_scanner_sdk-1.0.6-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48eeaff80d2377d43ef16dec45d22ec6b5eb5e5102ff16746e9eb113b9a846fd
|
|
| MD5 |
ef216e9cec0c181b388c49e249c9fea2
|
|
| BLAKE2b-256 |
aefa49c07a91c025da5e9b713187ae72d55063494feaeb5d1a1b6e418bf00afc
|
File details
Details for the file mrz_scanner_sdk-1.0.6-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: mrz_scanner_sdk-1.0.6-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b32bacd2c84c155df7311b45adf513e7f5a7462b71307d8d92dcbfa68c1651ee
|
|
| MD5 |
158238eba1a6a1eb9ff9d489db685ad7
|
|
| BLAKE2b-256 |
720087c12baf121fdb27618e40b812e85fd0da3d4b52acc07b5040b20f444f44
|
File details
Details for the file mrz_scanner_sdk-1.0.6-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: mrz_scanner_sdk-1.0.6-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2630d6bbc1e5a4270b59455004d034f4b50a57619cff13a4059445a9ddc212a8
|
|
| MD5 |
fe5cb2cd21f672fae646178e5f40000e
|
|
| BLAKE2b-256 |
bb70674001df4579d91568c08222b991cd3e079db22db13de53fb1ac4ff366c9
|
File details
Details for the file mrz_scanner_sdk-1.0.6-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: mrz_scanner_sdk-1.0.6-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3b17df641a227abeb72def6084c9f6ed1fc9af495c36bac629fe65d8e4649e3
|
|
| MD5 |
222cc42c35b18a915a08c41df27f091c
|
|
| BLAKE2b-256 |
923ee6e1314c22dfec130f8eeda7e23182a3b6221b1d69559b363c39b85c228e
|