Barcode and QR code scanning SDK for Python
Project description
Python Extension: Barcode and QR Code SDK
The project uses CPython to bind Dynamsoft C/C++ Barcode Reader SDK. It aims to help developers build Python barcode and QR code scanning apps on Windows, Linux, macOS, 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 = 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 cv2 import barcodeQrSDK import time import numpy as np # set license barcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==") # initialize barcode reader reader = barcodeQrSDK.createInstance() def get_time(): localtime = time.localtime() capturetime = time.strftime("%Y%m%d%H%M%S", localtime) return capturetime def read_barcode(): vc = cv2.VideoCapture(0) if vc.isOpened(): # try to get the first frame rval, frame = vc.read() else: return windowName = "Barcode Reader" while True: cv2.imshow(windowName, frame) rval, frame = vc.read() results = reader.decodeMat(frame) if (len(results) > 0): print(get_time()) print("Total count: " + str(len(results))) for result in results: print("Type: " + result.format) print("Value: " + result.text + "\n") 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(frame, [np.array([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2) # 'ESC' for quit key = cv2.waitKey(20) if key == 27: break cv2.destroyWindow(windowName) if __name__ == "__main__": print("OpenCV version: " + cv2.__version__) read_barcode()
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 = 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)
-
startVideoMode(maxListLength, maxResultListLength, width, height, imageformat, callback)
# start a native thread for decoding barcode and QR code in video modevideo_width = 640 video_height = 480 vc = cv2.VideoCapture(0) vc.set(3, video_width) #set width vc.set(4, video_height) #set height if vc.isOpened(): rval, frame = vc.read() else: return max_buffer = 2 max_results = 10 image_format = 1 # 0: gray; 1: rgb888 reader.startVideoMode(max_buffer, max_results, video_width, video_height, image_format, onBarcodeResult) def onBarcodeResult(data): results = data
-
appendVideoFrame()
# append a video frame to the internal buffer queue for decoding_, frame = vc.read() try: ret = reader.appendVideoFrame(frame) except: pass
-
stopVideoMode()
# stop the native threadreader.stopVideoMode()
-
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): 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 = scanner.decodeBytes(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], 1)
-
decodeBytesAsync
# decode image byte array asynchronouslydef callback(results): print(results) import cv2 image = cv2.imread("test.png") imagebytes = image.tobytes() scanner.decodeBytesAsync(image.tobytes(), len(imagebytes), image.shape[1], image.shape[0], image.strides[0], 1) 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.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5afcbea214976f5989f6ee863740e73d5f9ea96458d8df51466c53f3250c8d8 |
|
MD5 | 54e1488357827afef8db1a2eca0e1e89 |
|
BLAKE2b-256 | 1c20021ec1f020cb32cc06e47ab4b713c89dcef65e17c07566be2d76bea3dbbe |
Hashes for barcode_qr_code_sdk-9.4.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27cf606a6387df83de2889d0220ba72aaac2f554dae3fb4fbc1388b7d9d0b181 |
|
MD5 | f7ba13d4f9161da03a08b5431cf606bf |
|
BLAKE2b-256 | 9efbbdea69b409d3358df90f534f333d9f481bacda0317a000e584a62ec357f5 |
Hashes for barcode_qr_code_sdk-9.4.1-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c726b11633a255d1586ac684489377cb4bc3d42944cdb96a1fc02869900abfa |
|
MD5 | 65618fca49543a6672c30e23954aa14a |
|
BLAKE2b-256 | 42efa4bfa8082ea98d8b52d1d552f60756022635f22c7cae5ea90343dfbb3429 |
Hashes for barcode_qr_code_sdk-9.4.1-cp310-cp310-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a19b4c0b2155b828a4d0eeadbd926caf75bfc5a5fd452954ab68e0b0011f3e7 |
|
MD5 | a37c7e0c5c702b536616b6d9b7282a88 |
|
BLAKE2b-256 | e2db74d47c48a776c1830025b8c3fa19dacf0210d25cb3e73bababddbf82a77e |
Hashes for barcode_qr_code_sdk-9.4.1-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91146a7aa52e06ec4bc91e125fcad81a1eaea241eec7ffa6343c956d551c10c5 |
|
MD5 | 48211c1407f0fab4bd565aa72cacb275 |
|
BLAKE2b-256 | 5115c75c3f671e8af453f0953bf62b168aeb12d0cef1557130eba1c97a6fe5eb |
Hashes for barcode_qr_code_sdk-9.4.1-cp310-cp310-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2a60dc4d115c55e2210fc6ae6c171f153b9e63dfe40eebe5272b33d18317ba8 |
|
MD5 | 7334209edb64a8f4ffe36f2a0f7d59e4 |
|
BLAKE2b-256 | c3c3e1e80c9e926d4917ee39e634220f0ddde7131c8cdac560890924006bb06c |
Hashes for barcode_qr_code_sdk-9.4.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ee51e475bc635873d7fb05db681b06457722f9533504e911f58e4891a47a9d3 |
|
MD5 | 86d3ced0056ccb12ab4e38742442dbd1 |
|
BLAKE2b-256 | 4fc4f94f9507fd3a3521e5ffdfcdb0b9c5b0cd7e5c5182f5c3275254b3a36639 |
Hashes for barcode_qr_code_sdk-9.4.1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca92a056fa03fed08bcff8ccdd533f130e1737aaf3ff0ca325816d64e3df1067 |
|
MD5 | 8bee43d6e42da74a9f6a26142ca2b2f6 |
|
BLAKE2b-256 | da8a288c4f33b6821558d90fc6becf0ee6ee5d3d69f23dc06d1296607ca28594 |
Hashes for barcode_qr_code_sdk-9.4.1-cp39-cp39-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb2220dbcd44f59df53998a050366775cf5fd3267f01da9a7e5c10b20419f21 |
|
MD5 | cc04bcb05b897a034727b4cef6ccb49c |
|
BLAKE2b-256 | 60fec039fe688a77a58537666ea5fb33383e169bdf3d96886a4033f2534e018c |
Hashes for barcode_qr_code_sdk-9.4.1-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d57109b77d17744810ab6787098fcfca62c6fcc79f96f3dbe3afa37ab6c06391 |
|
MD5 | 71f9dfea4aa552789c51599b92b315e2 |
|
BLAKE2b-256 | 49c35305d69f1f320968c78474151221271a6cba20207271b0e2144d852dd869 |
Hashes for barcode_qr_code_sdk-9.4.1-cp39-cp39-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc37163bcef238fa536a7343e8dad1dbc1355a48330181277e183c4756262a64 |
|
MD5 | ba8c45d6d7b4d35a59f2fb0a4a0e8b7a |
|
BLAKE2b-256 | f7c620b27d83612d6a61bc39ae5432afc5d84ed298a49fb28e1805175ef29cbd |
Hashes for barcode_qr_code_sdk-9.4.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05c452b915bccd60c1917aa5d09f0063f4588e9035d3338a4aa8b9b8e4c74fcc |
|
MD5 | 897b3acadd4c61bcc4301eaf7c8fefaa |
|
BLAKE2b-256 | c1cbc2c882e10a5f3290d2e65d2392c36556c7c495157640abb40fd3ac62071e |
Hashes for barcode_qr_code_sdk-9.4.1-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d551fddc1f55c16efe2fa1f6435a4ec4e3da2ab6a36d7763f9a1a8bd96a872bd |
|
MD5 | 1ec4082ebaa4e9b98805544238c3925a |
|
BLAKE2b-256 | 9d5401cf287c6d860d774ef4abac6da76a7f3567613376c0d3e3f161f42e068b |
Hashes for barcode_qr_code_sdk-9.4.1-cp38-cp38-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf38d1984f1fdf9c8acb4f773be37f4a262fa3d92da979bc093a8dce724cb1b |
|
MD5 | 16fd93998c84e4d656552232db582650 |
|
BLAKE2b-256 | 3055d437f5be7793fae3af9938236cab71792f351105b1eedca121f8c8802a88 |
Hashes for barcode_qr_code_sdk-9.4.1-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c893deaae8fb75853206b7076c19d8941bc3c7b132a9c665546b56d090eeb492 |
|
MD5 | b4bb911571b776eab7704b648313a569 |
|
BLAKE2b-256 | d48638844a870d00b8c5c457fb6864ee8863d48777c629706ccca0c7a3daabe9 |
Hashes for barcode_qr_code_sdk-9.4.1-cp38-cp38-macosx_10_13_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71084193a289acdadf8bee7d78deeae0f88c5f2e68a098d4dc13240ffb953282 |
|
MD5 | c04c9fba59b973c948d232fcabb87577 |
|
BLAKE2b-256 | 2f14ea637c455d600826a695074ed9c2949d9ddcaabc25b039f7b5da0b15f7b5 |
Hashes for barcode_qr_code_sdk-9.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ede3d690c3b73c0ba88ac1ebb19a55380d89cc56506d495197cda4720f01a13 |
|
MD5 | bfbfcf0411e505baad1db168f1afdd78 |
|
BLAKE2b-256 | bea75a43a7b7b9055860be368d0eed581d85977ecaab91dd5ecd96982374ac01 |
Hashes for barcode_qr_code_sdk-9.4.1-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d09bf00a4dcc3e990a0f2a198f209c9a025527d65493c4e66cc8194e6f62f24 |
|
MD5 | 5baa42a099cd99f7e0df7a2afa452bfd |
|
BLAKE2b-256 | 5455e4dcbb39d3744239fa4ea2b241ba50b87de1482d767268e30778b8e9cdc7 |
Hashes for barcode_qr_code_sdk-9.4.1-cp37-cp37m-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81fcd2022ddbe86de11fe6587f33aa253c5c4f58c2ce7e09a74a5ed97940df7c |
|
MD5 | 286b21ecdcb74f76d90914234d8d4341 |
|
BLAKE2b-256 | ee955dbeef444e2019d43e9e54b3160d1188bf067c11eaf54ac30d78aada99b6 |
Hashes for barcode_qr_code_sdk-9.4.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc11a34eb1ded2fabdc77499e600b11b7a570054aa70c5631cdf844e8b29bdb8 |
|
MD5 | b272afb7c777199af915fa4c3209787f |
|
BLAKE2b-256 | e5bf42c42825ec1e34d8a175ba71f7d7ee12b9d6b0278c1dc7e8a594b3652960 |
Hashes for barcode_qr_code_sdk-9.4.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b409f5a9addf2acb9d2a9297c0d4d2b5e4903e82e6d66f2cfcfa5ac8132727fe |
|
MD5 | 7f08bbe7e098b533f96b1df8214ebb70 |
|
BLAKE2b-256 | d07008820a619f71e0aca99b89808e702a9672ab21910dcbd8eef6cbcbe32d06 |
Hashes for barcode_qr_code_sdk-9.4.1-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8522568f9ff24b720c486c1cf7286e1f1cbcf589b0b3e9dc70a794170a99e880 |
|
MD5 | ac96532836125887a7d62385915084dc |
|
BLAKE2b-256 | d7cce6ccadee7d4d95a97fd63ad36bbdfc42be1000456b9aa841ea19cc4fbf16 |
Hashes for barcode_qr_code_sdk-9.4.1-cp36-cp36m-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa1f0b0ff96c542484a62b6c777c89cc2857726714bccb018565b463bc8dc592 |
|
MD5 | 20dcd5fc2525c52df883c516c88b420a |
|
BLAKE2b-256 | 140352bc4be1c20c1e41500361fc93db28128a5d45d180f7437b615cd6d63c61 |
Hashes for barcode_qr_code_sdk-9.4.1-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 602cbf7e358506e22f2eadc42072d12d032422a5680148baa5db4e7517e8bbef |
|
MD5 | 273cd9d7a235511255e77e91e7086a96 |
|
BLAKE2b-256 | 2e9ff7774435bede1a7b02931bf316f1f5126bcb4bf70bafa8d032965beb0004 |