Barcode and QR code scanning SDK for Python
Project description
Python Extension: Barcode and QR Code SDK
The project is a CPython binding to Dynamsoft C/C++ Barcode Reader SDK. It aims to help developers build Python barcode and QR code scanning apps on Windows
, Linux
and macOS
. Besides desktop PCs, it can work well on embedded and IoT devices such as Raspberry Pi
and Jetson Nano
. You are free to customize the Python API for Dynamsoft Barcode Reader.
About Dynamsoft Barcode Reader
- Dynamsoft C/C++ Barcode Reader SDK v9.4.0
- Get a 30-day FREE trial license to activate the SDK.
Supported Python Edition
- Python 3.x
Install Dependencies
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>
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("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") reader = barcodeQrSDK.createInstance() results, elapsed_time = reader.decodeFile("test.png") 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("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") # 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()
Methods
-
barcodeQrSDK.initLicense('YOUR-LICENSE-KEY')
# set barcode SDK license globallybarcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
-
barcodeQrSDK.createInstance()
# create a barcode reader instancereader = barcodeQrSDK.createInstance()
-
decodeFile(filename)
# decode barcode and QR code from an image fileresults, elapsed_time = reader.decodeFile("test.png")
-
decodeMat(Mat image)
# decode barcode and QR code from Matimage = cv2.imread("test.png") 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()
# return JSON stringparams = reader.getParameters()
-
setParameters(JSON string)
# set barcode SDK parametersimport 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)
# start a native thread and register a Python function for receiving barcode QR code results -
decodeMatAsync(<opencv mat data>)
# decode barcode QR code from OpenCV Mat asynchronouslydef callback(results, elapsed_time): print(results) import cv2 image = cv2.imread("test.png") reader.addAsyncListener(callback) reader.decodeMatAsync(image) sleep(1)
-
clearAsyncListener()
# stop the native thread and clear the registered Python function -
decodeBytes(bytes, width, height, stride, imageformat)
# 0: gray; 1: rgb888import cv2 image = cv2.imread("test.png") results, elapsed_time = scanner.decodeBytes(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
-
decodeBytesAsync
# decode image byte array asynchronouslydef callback(results, elapsed_time): print(results) import cv2 image = cv2.imread("test.png") imagebytes = image.tobytes() scanner.decodeBytesAsync(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888) sleep(1)
Online Documentation for Dynamsoft C/C++ Barcode SDK
To customize Python API based on C/C++, please refer to the online documentation.
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
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
Hashes for barcode-qr-code-sdk-9.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 669dc1d72c6329961acd3acbf5049151346c8e6f72347a7a0c0cff31c6e3756e |
|
MD5 | 46a2f23bd95172846abf9475c914304a |
|
BLAKE2b-256 | c9c15ae59f3c98a4bdaa3b861656ce6fe34548a10bbb3d1865bb1f47c7b6dadf |
Hashes for barcode_qr_code_sdk-9.5.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df9b026914d20b75aa33daad7eb60bab9d7b2a7d7bbb1a46435e6652d4f72e2 |
|
MD5 | 1c183af9422c374f6f9b3d2031097694 |
|
BLAKE2b-256 | b4300f561ebfe6db2b564321fd26f4d5850416b67530152d0b4e307783f2caf6 |
Hashes for barcode_qr_code_sdk-9.5.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe6b6c26cc0e96bd1424959af8f2deeeed2f0bc1a8f9cefd438f0f60b72d3368 |
|
MD5 | f34184155b4a6492fc2baed2edc32e2b |
|
BLAKE2b-256 | 6981aa046dc66ee7f765614fd3d18b23a23d7b40f936f1df60287bded7dcf0bb |
Hashes for barcode_qr_code_sdk-9.5.0-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c792b7820d103f1b3d638889a6b047a46fb97a0b27a6160df67d420f4699ea1 |
|
MD5 | abeb7325b5aa9fd06dbbb61ff94c825a |
|
BLAKE2b-256 | 15dbd95fd1718fe62bbf912059146ddc4e3278d173d640af8c4c1382dc45af39 |
Hashes for barcode_qr_code_sdk-9.5.0-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4b2b6c182f42dafe7f11bb9d6d40bcbe6a7b18db50d46432a2da06d714c3225 |
|
MD5 | 43cd00add2864fe6abe1949f7b54ac10 |
|
BLAKE2b-256 | 46288e424c982953601a7d8abf21bc4adb38b10d71d3723a1bd83c581597c858 |
Hashes for barcode_qr_code_sdk-9.5.0-cp310-cp310-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d6ef3a18364f641d47e9909a13625598e87beb5e9477552b2220ca1b1a826f5 |
|
MD5 | b685526942fba07a92c60ed1d0e5a635 |
|
BLAKE2b-256 | e94289f5753e98e6288eab69afa615e98179ff12f6f3a72bbc42b1b936f8b239 |
Hashes for barcode_qr_code_sdk-9.5.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d858cf34ce77a053c6aa29268480cb4d814fa757dd33424047433bebe03e744e |
|
MD5 | 5b14299925b328cc12da2ee3835643b1 |
|
BLAKE2b-256 | b6f95738519264c0cb9534e55c3933775717ccf07fa775bd29c717df388653e2 |
Hashes for barcode_qr_code_sdk-9.5.0-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f407d3554fe71834bcb5da9d4d18884dad83833fcef8662f0e686ab50471ec2a |
|
MD5 | f93247cca23655ff364cd3c80eaea195 |
|
BLAKE2b-256 | ffd3a8c71c968216f85096f377dc33b45c1f2d5417c33b77300c9b19144099ee |
Hashes for barcode_qr_code_sdk-9.5.0-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c6856151a10bd369e0471e4142c9289c144202df6148ed3f83bcd9223500c7d |
|
MD5 | 7e0b66072aa88fb7bfaf6c523951852c |
|
BLAKE2b-256 | 40e191923eef408812cc9bd5d97b2ac71419f1ca1bae9562c5014fe87a6ac405 |
Hashes for barcode_qr_code_sdk-9.5.0-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28a7bae4ead083fcc058337076d2ba5c790bb906322fff3af8774add19a4c4a5 |
|
MD5 | 80ca6736fc4fcda6e9b6711dd0166f29 |
|
BLAKE2b-256 | 04aa378b919d260dd71900fdd3ff021c7b05ce15101c8939f3d30c6a660cbdea |
Hashes for barcode_qr_code_sdk-9.5.0-cp39-cp39-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d5fb96eea134b9336be3f9f35809108b3263f4fa0ba506dc4bd0f9a75e2ab58 |
|
MD5 | e561c53af7a807a885ad1b4b2768fc15 |
|
BLAKE2b-256 | 459aea478698255d21f54db74a53dbe52c001d86a2755e84c8bf235d7b48e2fd |
Hashes for barcode_qr_code_sdk-9.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e7875296537e95a3101d46f0eb07b2c1b6e9523fd38eb50354703b40f41ab8d |
|
MD5 | c8f90efcbbb1750e3450d0d4b68a41e0 |
|
BLAKE2b-256 | d4e178a2220df15361fd64c4cf1801cd0b5990394ba4d4f8064bb2663e233941 |
Hashes for barcode_qr_code_sdk-9.5.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1768d811404d63766f7bb59ef9f3a76321094f650fb2d1a241887e75d9400e92 |
|
MD5 | 6ba0a4eaa1f94d778f266dcd696b9796 |
|
BLAKE2b-256 | 832e9ad0480a79c3916d3570ee678222fb53c4b842ee96d29d96926c1b3b0de3 |
Hashes for barcode_qr_code_sdk-9.5.0-cp38-cp38-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5a917254a4b2a44841ee15fe56169a038746d8685d990ae1f519ebb9ce3c4ba |
|
MD5 | 0fc10df8e6e63ff29304b04f5057076c |
|
BLAKE2b-256 | c775b419b549c786fb51d0e86975ef8ef713129bcc35ea9d08857bbce90d9757 |
Hashes for barcode_qr_code_sdk-9.5.0-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1b75043488ca6d84b24333af1702ef422749a01f9793efecaea25f3ab6f5216 |
|
MD5 | 5fcd67ab59897c716d955aeabc7aeabb |
|
BLAKE2b-256 | 4bbc5c3868c79f552f47a1d2dbb1799ae63f7246be10384e8d75de13fbf098f2 |
Hashes for barcode_qr_code_sdk-9.5.0-cp38-cp38-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5246dc84b375fd0147dc706941f33def7dbd6a826398b3ae194d6f31efc0f3a |
|
MD5 | 9bd1884716f8d9f1abab721d66669a66 |
|
BLAKE2b-256 | def898332e68f78f1d0a035eb818114c227a3424b4c1585ab43791585555f5ee |
Hashes for barcode_qr_code_sdk-9.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5b20216ed762f03bf9aae8db84a34ec7abba38cec48e9cb2ad548b58eaaddec |
|
MD5 | 48bb8fb0219c515c1078716b5b1ab1b2 |
|
BLAKE2b-256 | 33332e38d48f0a92c945971490209e55ac67238f2da8b65ba8aff85b265596e9 |
Hashes for barcode_qr_code_sdk-9.5.0-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f519152449018b9f7ea93bd65cb99fb2048f4a4ab391b6f855ddd5b7f8f0771 |
|
MD5 | cc47ec1582907ae81f8e939a5903fa59 |
|
BLAKE2b-256 | 54caac9f39f520f00275f54c475245a0d490c2247fffa8e608e12401ef99fe67 |
Hashes for barcode_qr_code_sdk-9.5.0-cp37-cp37m-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e09fd49d832a472ea4908eab8a8e578fe52fd4fd534ea7b2384c6387bab9905 |
|
MD5 | 6e49bdea85acdc64082dbf1fa4ff84f4 |
|
BLAKE2b-256 | 846d8e19103b01ee3eb48c44c013757fdd0506cb5f077080e2ded59feebf6796 |
Hashes for barcode_qr_code_sdk-9.5.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96665a464b9c5361adf897fada7067493730afc8b260876c259a134a6ec0dcb9 |
|
MD5 | 36e73af7d213d702659d8bdc4112efab |
|
BLAKE2b-256 | 4e85eb18b53749d4cd8ff26750cc4f4d0dd4f2b90a2be2e0ee74af775ff9ad37 |
Hashes for barcode_qr_code_sdk-9.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36c9496d551b77e35f5c26e0cee61b93eec027c90d097dcf4cda2db117387cdf |
|
MD5 | 5744a1439260e8e64d7ab8199b1a161f |
|
BLAKE2b-256 | 4c8414ac83866d63fc3d932aa35458b03257bb7dab582795966bea61ff8ff16f |
Hashes for barcode_qr_code_sdk-9.5.0-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcd6ad7f4feb9c58113ee995b597fe43473241a9b868e191511e29e116e4ca1e |
|
MD5 | f38384c3aeeda3e38753e05979338f89 |
|
BLAKE2b-256 | 1b109ef12fd18016887188613c750e9b71e821f391c4a7be283f557319819384 |
Hashes for barcode_qr_code_sdk-9.5.0-cp36-cp36m-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91deca5607751a230af2a94912e6337b322d17d449fd2b204631430ad56cb6d6 |
|
MD5 | 1e492bf2ab0a8c57fa0812988da494f4 |
|
BLAKE2b-256 | 53a737baaff160fc83971d33f1670cda258d58c751eff091af09ec4ced4d427c |
Hashes for barcode_qr_code_sdk-9.5.0-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59c87a816d64c2b2e566e1a1d6b2217f4c567a51f893dbdfab8a68a0519a3b0b |
|
MD5 | 3362ab841187860ded8ec036d13e2d07 |
|
BLAKE2b-256 | 9296828b770cb09ae379b97fd654e36158c335601e29a4b3b61bfa62b4567373 |