yushulx / python-mrz-scanner-sdk

Python MRZ scanner SDK built with Dynamsoft Label Recognizer
https://pypi.org/project/mrz-scanner-sdk/
MIT License
5 stars 0 forks source link
cpython idcard machine-readable-zone mrz ocr passport python python-extension python3 visa wheel

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.

Note: This project is an unofficial, community-maintained Python wrapper for the Dynamsoft Label Recognizer SDK. For those seeking the most reliable and fully-supported solution, Dynamsoft offers an official Python package. Visit the Dynamsoft Capture Vision Bundle page on PyPI for more details.

About Dynamsoft Capture Vision Bundle

Comparison Table

Feature Unofficial Wrapper (Community) Official Dynamsoft Capture Vision SDK
Support Community-driven, best effort Official support from Dynamsoft
Documentation README only Comprehensive Online Documentation
API Coverage Limited Full API coverage
Feature Updates May lag behind the official SDK First to receive new features
Compatibility Limited testing across environments Thoroughly tested across all supported environments
OS Support Windows, Linux Windows, Linux, macOS

Supported Python Versions

Installation

Install the required dependencies:

pip install mrz opencv-python

Command-line Usage

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

How to Build the Python MRZ Scanner Extension