Skip to main content

Barcode and QR code scanning SDK for Python

Project description

Python Extension: Barcode and QR Code SDK

This project provides a CPython binding to the Dynamsoft C/C++ Barcode Reader SDK v9.x. It demonstrates how to build a Python 1D/2D barcode SDK package for Windows, Linux and macOS from scratch. Beyond desktop PCs, it's also compatible with embedded and IoT devices such as Raspberry Pi and Jetson Nano. You are free to customize the Python API for Dynamsoft Barcode Reader to suit your specific needs.

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

About Dynamsoft Python Barcode SDK

Comparison Table

Feature Unofficial Wrapper (Community) Official Dynamsoft Python Barcode 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

Supported Python Edition

  • Python 3.x

Installation of Dependencies

To show UI, you need to install the OpenCV package:

pip install opencv-python

Command-line Usage

$ scanbarcode <file-name> -l <license-key>

# Show the image with OpenCV
$ scanbarcode <file-name> -u 1 -l <license-key>

python barcode QR code scanner

How to Build the Python Barcode and QR Code Extension

  • Create a source distribution:

    python setup.py sdist
    
  • setuptools:

    python setup_setuptools.py build
    python setup_setuptools.py develop # Copy libraries to barcodeQrSDK folder
    
  • scikit-build:

    python setup.py build
    python setup.py develop # Copy libraries to barcodeQrSDK folder
    
  • Build wheel:

    pip wheel . --verbose
    # Or
    python setup_setuptools.py bdist_wheel
    # Or
    python setup.py bdist_wheel
    

Quick Start

  • Console App

    import barcodeQrSDK
    
    # set license
    barcodeQrSDK.initLicense("LICENSE-KEY")
    
    reader = barcodeQrSDK.createInstance()
    
    results, elapsed_time = reader.decodeFile("IMAGE-FILE")
    for result in results:
        print(result.format)
        print(result.text)
        print(result.x1)
        print(result.y1)
        print(result.x2)
        print(result.y2)
        print(result.x3)
        print(result.y3)
        print(result.x4)
        print(result.y4)
    
  • Video App

    import barcodeQrSDK
    import numpy as np
    import cv2
    import json
    
    g_results = None
    
    def callback(results, elapsed_time):
        global g_results
        g_results = (results, elapsed_time)
    
    def run():
        # set license
        barcodeQrSDK.initLicense("LICENSE-KEY")
    
        # initialize barcode scanner
        scanner = barcodeQrSDK.createInstance()
        params = scanner.getParameters()
        # Convert string to JSON object
        json_obj = json.loads(params)
        # json_obj['ImageParameter']['ExpectedBarcodesCount'] = 999
        params = json.dumps(json_obj)
        ret = scanner.setParameters(params)
        
        scanner.addAsyncListener(callback)
    
        cap = cv2.VideoCapture(0)
        while True:
            ret, image = cap.read()
            if image is not None:
                scanner.decodeMatAsync(image)
                
            if g_results != None:
                print('Elapsed time: ' + str(g_results[1]) + 'ms')
                cv2.putText(image, 'Elapsed time: ' + str(g_results[1]) + 'ms', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
                for result in g_results[0]:
                    x1 = result.x1
                    y1 = result.y1
                    x2 = result.x2
                    y2 = result.y2
                    x3 = result.x3
                    y3 = result.y3
                    x4 = result.x4
                    y4 = result.y4
                    
                    cv2.drawContours(image, [np.int0([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2)
                    cv2.putText(image, result.text, (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
    
            cv2.imshow('Barcode QR Code Scanner', image)
            ch = cv2.waitKey(1)
            if ch == 27:
                break
        
        scanner.clearAsyncListener()
    
    if __name__ == '__main__':
        run()
    

    Python barcode and QR code scanner

Methods

  • barcodeQrSDK.initLicense('YOUR-LICENSE-KEY'): Set the global license key for the barcode SDK.

    barcodeQrSDK.initLicense("LICENSE-KEY")
    
  • barcodeQrSDK.createInstance(): Create a new barcode reader instance.

    reader = barcodeQrSDK.createInstance()
    
  • decodeFile(filename): Decode barcodes and QR codes from an image file.

    results, elapsed_time = reader.decodeFile("IMAGE-FILE")
    
  • decodeMat(Mat image): Decode barcodes and QR codes from an OpenCV Mat.

    image = cv2.imread("IMAGE-FILE")
    results = reader.decodeMat(image)
    for result in results:
        print(result.format)
        print(result.text)
        print(result.x1)
        print(result.y1)
        print(result.x2)
        print(result.y2)
        print(result.x3)
        print(result.y3)
        print(result.x4)
        print(result.y4)
    
  • getParameters(): Retrieve the current SDK parameters as a JSON string.

    params = reader.getParameters()
    
  • setParameters(JSON string): Set barcode SDK parameters using a JSON string.

    import json
    json_obj = json.loads(params)
    json_obj['ImageParameter']['DPMCodeReadingModes'][0]['Mode'] = 'DPMCRM_GENERAL'
    json_obj['ImageParameter']['LocalizationModes'][0]['Mode'] = 'LM_STATISTICS_MARKS'
    params = json.dumps(json_obj)
    ret = reader.setParameters(params)
    
  • addAsyncListener(callback function): Register a Python function to receive barcode results asynchronously.

  • decodeMatAsync(<opencv mat data>): Asynchronously decode barcodes and QR codes from an OpenCV Mat.

    def callback(results, elapsed_time):
        print(results)
                                                        
    import cv2
    image = cv2.imread("IMAGE-FILE")
    reader.addAsyncListener(callback)
    reader.decodeMatAsync(image)
    sleep(1)
    
  • clearAsyncListener(): Stop the asynchronous listener and clear the registered callback.

  • decodeBytes(bytes, width, height, stride, imageformat): Decode barcodes from a raw image byte array.

    import cv2
    image = cv2.imread("IMAGE-FILE")
    results, elapsed_time = scanner.decodeBytes(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
    
  • decodeBytesAsync: Asynchronously decode image byte arrays.

    def callback(results, elapsed_time):
        print(results)
                                                        
    import cv2
    image = cv2.imread("IMAGE-FILE")
    imagebytes = image.tobytes()
    scanner.decodeBytesAsync(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
    sleep(1)
    

Supported Barcode Symbologies

  • Linear Barcodes (1D)

    • Code 39 (including Code 39 Extended)
    • Code 93
    • Code 128
    • Codabar
    • Interleaved 2 of 5
    • EAN-8
    • EAN-13
    • UPC-A
    • UPC-E
    • Industrial 2 of 5
  • 2D Barcodes:

    • QR Code (including Micro QR Code)
    • Data Matrix
    • PDF417 (including Micro PDF417)
    • Aztec Code
    • MaxiCode (mode 2-5)
  • Patch Code

  • GS1 Composite Code

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

barcode_qr_code_sdk-9.6.40.tar.gz (60.9 MB view details)

Uploaded Source

Built Distributions

barcode_qr_code_sdk-9.6.40-cp310-cp310-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.10 Windows x86-64

barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.24+ ARM64

barcode_qr_code_sdk-9.6.40-cp39-cp39-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.9 Windows x86-64

barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ ARM64

barcode_qr_code_sdk-9.6.40-cp38-cp38-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.8 Windows x86-64

barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.24+ ARM64

barcode_qr_code_sdk-9.6.40-cp37-cp37m-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.7m Windows x86-64

barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.24+ ARM64

barcode_qr_code_sdk-9.6.40-cp36-cp36m-win_amd64.whl (10.7 MB view details)

Uploaded CPython 3.6m Windows x86-64

barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_x86_64.whl (11.7 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_aarch64.whl (10.9 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.24+ ARM64

File details

Details for the file barcode_qr_code_sdk-9.6.40.tar.gz.

File metadata

  • Download URL: barcode_qr_code_sdk-9.6.40.tar.gz
  • Upload date:
  • Size: 60.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for barcode_qr_code_sdk-9.6.40.tar.gz
Algorithm Hash digest
SHA256 7019460c4389559f7d3d2171077df8473eb4be136b3abe7bb42dcffa95db7258
MD5 33f6bf6cf253abd3b056387c0948e26a
BLAKE2b-256 fa4d8378213df8ba0b91fc4837b84306fff6f663ba18a56f33986ed5e1c5d10e

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 24533a707e4733933fe70f83e0d60bd4f56e3967d1405a8e460ec88e171513df
MD5 31114e1d81a37746acbee38ab0afef05
BLAKE2b-256 9548645031bd893b00a2c1bbca4e8ed5edc9e67d7ed0bfe632b7073e1a60c76c

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 3873f615b07ddd840ed6f40555da347fe96b0e3fdffe00461b1c335a159fac9a
MD5 628112e6627051f903a459c5a709b4b5
BLAKE2b-256 e653c2502eba7c991f0b00989b6b0a24ed135768964c70fdd976d3555c60710d

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 f9215946a34ed120c0f91a427700a02dcafa48cb83b9d4884195b34967f2b87f
MD5 31d123e0b8c841885ad50bceaf1976d9
BLAKE2b-256 c62dec9253e3112060feee3797fdbc9e4dbe2d5fce2a12417b7de4ac376a3a9b

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 af6079c7939b959e249c6bad0d8bf0bff802f4fdcc3c7b704c92bf62438cb7e5
MD5 3a394f5077b63432d6f8276240e7474d
BLAKE2b-256 5b51d9ca4fdad946361036aa7d554362146c6ff76fa025f9c83ba6fa0ec37f38

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 66df2702707989f5201d263d5342620a8ebd7dc6902cbe486ae2b8abd34e126c
MD5 a61366729805243f38e553a3fb6bf501
BLAKE2b-256 3bf867ff042f0d5227e680c7ffd9898a94879bdc321f3167485181d579f9eb6d

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 0d9c7865ec6b067cccc996a98da614e29f53ba254e4da34dec674da9253b0881
MD5 ae62bed43ea70f2168aa3590b8dd5522
BLAKE2b-256 0a71542b1459a563ec142552e7e82189af3367b9d652380904e4ce07653ff53e

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ccee20ef7ad1329d72819b00e2b325fbc310c1a01a40f8497f0fe2921ac8a455
MD5 fdff4c4b212a60d36de8c6db07205c0a
BLAKE2b-256 71bb1c7026554bcf57cf78d613f5fb5138c7b3e6962a2042b3d9f0b42c805f82

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 2c73ec8dac5a05ccb89134877bc66ef6cd38322aa760305f2546507614afa8c8
MD5 e90fbdbbb93b715a11c04757e7df24aa
BLAKE2b-256 61bd35296c6d817c9e971d5a70c998ff8cc61438ea72a4c422488946cb8dbb99

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp38-cp38-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 c2becfd17691a1d84a49e49fd05f07f14dfe3631ab54fe122d255180da9186a1
MD5 b507410a6f538a0b197a3c621ca192a8
BLAKE2b-256 563ed502314301c950049fc444ec302f21cc5a1a11b35df13777ffa4bdbc6f9d

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a4f7d8d98f91e9b247157b6bfb905178bcee9342ac35872d4674d7d784f30e91
MD5 cbaa5a5c1387175454e3a39f12f3451b
BLAKE2b-256 049bf2ca8c8575e67db9a279fd035062d930fce13a6cf6f7dfe1f6e9072e99c7

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 408b411b9d7d9a93de636e8a1fc534652578d417c6efb36544b70b2b346818b9
MD5 59056e8d9f08ee416dd004e870733e56
BLAKE2b-256 e2862fb8b3ec96b7a3bf5d2b898669492317441ca3774b1755707e3d129a53f9

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp37-cp37m-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 9be4d233df638ee71ab3e8949731c80aea925bea6f786fb66d6f27dd85952b9e
MD5 7373aa19edd43586a16c4bf209470a06
BLAKE2b-256 38e1d770feee7aefe1738d8ee1897af9cf89dfaad3a42ed76c081b00543d7991

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 381f70512d2e1db684362ee8e7285853825573d5b05279243a3a5b3ef60af591
MD5 e0833cd126ff6d54cb0fe09e786c790a
BLAKE2b-256 7bdf2b17b49c2cf0f8f9ab152b69e6c1887ad379b891d408022b020a2a657f4a

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 a2076cb71add36196b3aa9f0d34d88e1d54f3bfb737ed9b9946941d9657b0362
MD5 7e5fdab1c366cc74026df4070d5e6581
BLAKE2b-256 6a5e879781a1bc6229451d32246397476c5942c7d0f953553b60a9cd9a5d5d7d

See more details on using hashes here.

File details

Details for the file barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for barcode_qr_code_sdk-9.6.40-cp36-cp36m-manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 2f80c0c8ebae93c4db8af7832f1e2e0bd37612590f1fd6185068e57683e1ea4c
MD5 fe7a31b6f50e045d53500aca042ed49d
BLAKE2b-256 2d28035334b09e94498ebdd95a81e1114f2b90b8b25a5ab3eeab9ebef481ad05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page