mrz-scanner-sdk


Namemrz-scanner-sdk JSON
Version 1.1.2 PyPI version JSON
download
home_pagehttps://github.com/yushulx/python-mrz-scanner-sdk
SummaryMachine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.
upload_time2024-10-17 06:53:24
maintainerNone
docs_urlNone
authoryushulx
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python MRZ Scanner SDK
This project provides a Python-C++ binding for the [Dynamsoft Label Recognizer v2.x](https://www.dynamsoft.com/label-recognition/overview/), 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](https://pypi.org/project/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](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform).
- Install the SDK via `pip install 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](https://www.dynamsoft.com/capture-vision/docs/server/programming/python/?lang=python) |
| 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
* Python 3.x

## Installation
Install the required dependencies:
```bash 
pip install mrz opencv-python
```

## Command-line Usage
- Scan MRZ from an image file:
    ```bash 
    scanmrz <file-name> -l <license-key>
    ```
- Scan MRZ from a webcam:
    ```bash 
    scanmrz <file-name> -u 1 -l <license-key>
    ```

    ![python mrz scanner](https://www.dynamsoft.com/codepool/img/2022/08/python-mrz-scanner.png)

## Quick Start
```python
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.
    
    ```python
    mrzscanner.initLicense("LICENSE-KEY")
    ```

- `mrzscanner.createInstance()`: Create an instance of the MRZ scanner.
    
    ```python
    scanner = mrzscanner.createInstance()
    ```
- `scanner.loadModel(<model configuration file>)`: Load the MRZ model configuration.
    
    ```python
    scanner.loadModel(mrzscanner.load_settings())
    ```
- `decodeFile(<image file>)`: Recognize MRZ from an image file.

    ```python
    results = scanner.decodeFile(<image-file>)
    for result in results:
        print(result.text)
    ```
- `decodeMat(<opencv mat data>)`: Recognize MRZ from an OpenCV Mat.
    ```python
    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.
    ```python
    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:
    
    ```bash
    python setup.py sdist
    ```

- setuptools:
    
    ```bash
    python setup.py build
    python setup.py develop 
    ```
- Build wheel:
    
    ```bash
    pip wheel . --verbose
    # Or
    python setup.py bdist_wheel
    ```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yushulx/python-mrz-scanner-sdk",
    "name": "mrz-scanner-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "yushulx",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e9/0a/fe383bc32b1835adcec77be2f15bb0eb0b48b1b8a50a763a8afc7ba9da28/mrz-scanner-sdk-1.1.2.tar.gz",
    "platform": null,
    "description": "# Python MRZ Scanner SDK\r\nThis project provides a Python-C++ binding for the [Dynamsoft Label Recognizer v2.x](https://www.dynamsoft.com/label-recognition/overview/), allowing developers to build **MRZ (Machine Readable Zone)** scanner applications on both **Windows** and **Linux** platforms using Python.\r\n\r\n> 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](https://pypi.org/project/dynamsoft-capture-vision-bundle/) page on PyPI for more details.\r\n\r\n## About Dynamsoft Capture Vision Bundle\r\n- Activate the SDK with a [30-day FREE trial license](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform).\r\n- Install the SDK via `pip install dynamsoft-capture-vision-bundle`.\r\n\r\n### Comparison Table\r\n| Feature | Unofficial Wrapper (Community) | Official Dynamsoft Capture Vision SDK |\r\n| --- | --- | --- |\r\n| Support | Community-driven, best effort | Official support from Dynamsoft |\r\n| Documentation | README only | [Comprehensive Online Documentation](https://www.dynamsoft.com/capture-vision/docs/server/programming/python/?lang=python) |\r\n| API Coverage | Limited | Full API coverage |\r\n|Feature Updates| May lag behind the official SDK | First to receive new features |\r\n| Compatibility | Limited testing across environments| Thoroughly tested across all supported environments|\r\n| OS Support | Windows, Linux | Windows, Linux, **macOS** |\r\n\r\n## Supported Python Versions\r\n* Python 3.x\r\n\r\n## Installation\r\nInstall the required dependencies:\r\n```bash \r\npip install mrz opencv-python\r\n```\r\n\r\n## Command-line Usage\r\n- Scan MRZ from an image file:\r\n    ```bash \r\n    scanmrz <file-name> -l <license-key>\r\n    ```\r\n- Scan MRZ from a webcam:\r\n    ```bash \r\n    scanmrz <file-name> -u 1 -l <license-key>\r\n    ```\r\n\r\n    ![python mrz scanner](https://www.dynamsoft.com/codepool/img/2022/08/python-mrz-scanner.png)\r\n\r\n## Quick Start\r\n```python\r\nimport mrzscanner\r\nfrom mrz.checker.td1 import TD1CodeChecker\r\nfrom mrz.checker.td2 import TD2CodeChecker\r\nfrom mrz.checker.td3 import TD3CodeChecker\r\nfrom mrz.checker.mrva import MRVACodeChecker\r\nfrom mrz.checker.mrvb import MRVBCodeChecker\r\n\r\ndef check(lines):\r\n    try:\r\n        td1_check = TD1CodeChecker(lines)\r\n        if bool(td1_check):\r\n            return \"TD1\", td1_check.fields()\r\n    except Exception as err:\r\n        pass\r\n    \r\n    try:\r\n        td2_check = TD2CodeChecker(lines)\r\n        if bool(td2_check):\r\n            return \"TD2\", td2_check.fields()\r\n    except Exception as err:\r\n        pass\r\n    \r\n    try:\r\n        td3_check = TD3CodeChecker(lines)\r\n        if bool(td3_check):\r\n            return \"TD3\", td3_check.fields()\r\n    except Exception as err:\r\n        pass\r\n    \r\n    try:\r\n        mrva_check = MRVACodeChecker(lines)\r\n        if bool(mrva_check):\r\n            return \"MRVA\", mrva_check.fields()\r\n    except Exception as err:\r\n        pass\r\n    \r\n    try:\r\n        mrvb_check = MRVBCodeChecker(lines)\r\n        if bool(mrvb_check):\r\n            return \"MRVB\", mrvb_check.fields()\r\n    except Exception as err:\r\n        pass\r\n    \r\n    return 'No valid MRZ information found'\r\n\r\n# set license\r\nmrzscanner.initLicense(\"LICENSE-KEY\")\r\n\r\n# initialize mrz scanner\r\nscanner = mrzscanner.createInstance()\r\n\r\n# load MRZ model\r\nscanner.loadModel(mrzscanner.load_settings())\r\n\r\nprint('')\r\n# decodeFile()\r\ns = \"\"\r\nresults = scanner.decodeFile(\"images/1.png\")\r\nfor result in results:\r\n    print(result.text)\r\n    s += result.text + '\\n'\r\nprint('')\r\nprint(check(s[:-1]))\r\nprint('')\r\n```\r\n\r\n## API Reference\r\n- `mrzscanner.initLicense('YOUR-LICENSE-KEY')`: Initialize the SDK with your license key.\r\n    \r\n    ```python\r\n    mrzscanner.initLicense(\"LICENSE-KEY\")\r\n    ```\r\n\r\n- `mrzscanner.createInstance()`: Create an instance of the MRZ scanner.\r\n    \r\n    ```python\r\n    scanner = mrzscanner.createInstance()\r\n    ```\r\n- `scanner.loadModel(<model configuration file>)`: Load the MRZ model configuration.\r\n    \r\n    ```python\r\n    scanner.loadModel(mrzscanner.load_settings())\r\n    ```\r\n- `decodeFile(<image file>)`: Recognize MRZ from an image file.\r\n\r\n    ```python\r\n    results = scanner.decodeFile(<image-file>)\r\n    for result in results:\r\n        print(result.text)\r\n    ```\r\n- `decodeMat(<opencv mat data>)`: Recognize MRZ from an OpenCV Mat.\r\n    ```python\r\n    import cv2\r\n    image = cv2.imread(<image-file>)\r\n    results = scanner.decodeMat(image)\r\n    for result in results:\r\n        print(result.text)\r\n    ```\r\n- `addAsyncListener(callback function)`: Register a callback function to receive MRZ recognition results asynchronously.\r\n- `decodeMatAsync(<opencv mat data>)`: Recognize MRZ from OpenCV Mat asynchronously.\r\n    ```python\r\n    def callback(results):\r\n        s = \"\"\r\n        for result in results:\r\n            print(result.text)\r\n            s += result.text + '\\n'\r\n    \r\n        print('')\r\n        print(check(s[:-1]))\r\n    \r\n    import cv2\r\n    image = cv2.imread(<image-file>)\r\n    scanner.addAsyncListener(callback)\r\n    for i in range (2):\r\n        scanner.decodeMatAsync(image)\r\n        sleep(1)\r\n    ```\r\n\r\n## How to Build the Python MRZ Scanner Extension\r\n- Create a source distribution:\r\n    \r\n    ```bash\r\n    python setup.py sdist\r\n    ```\r\n\r\n- setuptools:\r\n    \r\n    ```bash\r\n    python setup.py build\r\n    python setup.py develop \r\n    ```\r\n- Build wheel:\r\n    \r\n    ```bash\r\n    pip wheel . --verbose\r\n    # Or\r\n    python setup.py bdist_wheel\r\n    ```\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Machine readable zone (MRZ) reading SDK for passport, Visa, ID card and travel document.",
    "version": "1.1.2",
    "project_urls": {
        "Homepage": "https://github.com/yushulx/python-mrz-scanner-sdk"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bf122d71705b15ebffcb3e6e867ec4066370797a4662a70aa61b66321f58f34",
                "md5": "53e21f2cc2aad45b7270899cd0211ffd",
                "sha256": "40a614970eae7ce047f680e040bc1f6518f47bb489af54552dfa137feb8f42a7"
            },
            "downloads": -1,
            "filename": "mrz_scanner_sdk-1.1.2-cp310-cp310-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "53e21f2cc2aad45b7270899cd0211ffd",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 10055029,
            "upload_time": "2024-10-17T06:53:21",
            "upload_time_iso_8601": "2024-10-17T06:53:21.610453Z",
            "url": "https://files.pythonhosted.org/packages/5b/f1/22d71705b15ebffcb3e6e867ec4066370797a4662a70aa61b66321f58f34/mrz_scanner_sdk-1.1.2-cp310-cp310-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e90afe383bc32b1835adcec77be2f15bb0eb0b48b1b8a50a763a8afc7ba9da28",
                "md5": "fb5e2f31f6b1b53965505deeb86bfb1c",
                "sha256": "c88f323cc5b5f21b1f9b245ae5897bb25ecebf1697376d78988a9519d29292d8"
            },
            "downloads": -1,
            "filename": "mrz-scanner-sdk-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "fb5e2f31f6b1b53965505deeb86bfb1c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21403655,
            "upload_time": "2024-10-17T06:53:24",
            "upload_time_iso_8601": "2024-10-17T06:53:24.543072Z",
            "url": "https://files.pythonhosted.org/packages/e9/0a/fe383bc32b1835adcec77be2f15bb0eb0b48b1b8a50a763a8afc7ba9da28/mrz-scanner-sdk-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-17 06:53:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yushulx",
    "github_project": "python-mrz-scanner-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mrz-scanner-sdk"
}
        
Elapsed time: 0.94919s