Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mrz-scanner-sdk

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrz-scanner-sdk

Machine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.

  • 1.1.2
  • PyPI
  • Socket score

Maintainers
1

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

  • Activate the SDK with a 30-day FREE trial license.
  • Install the SDK via pip install dynamsoft-capture-vision-bundle.

Comparison Table

FeatureUnofficial Wrapper (Community)Official Dynamsoft Capture Vision SDK
SupportCommunity-driven, best effortOfficial support from Dynamsoft
DocumentationREADME onlyComprehensive Online Documentation
API CoverageLimitedFull API coverage
Feature UpdatesMay lag behind the official SDKFirst to receive new features
CompatibilityLimited testing across environmentsThoroughly tested across all supported environments
OS SupportWindows, LinuxWindows, Linux, macOS

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>
    

    python mrz scanner

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
    

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc