Skip to content

Commit d989611

Browse files
committed
Update DBR C++ SDK to v9.6.40
1 parent 596d251 commit d989611

32 files changed

+669
-324
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
_skbuild
22
/build
3+
dist

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
3030
link_directories("${PROJECT_SOURCE_DIR}/lib/aarch64/")
3131
endif()
3232
elseif(CMAKE_HOST_APPLE)
33-
if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
34-
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/lib/macos_arm64/" )
35-
link_directories("${PROJECT_SOURCE_DIR}/lib/macos_arm64/")
36-
else()
37-
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/lib/macos/" )
38-
link_directories("${PROJECT_SOURCE_DIR}/lib/macos/")
39-
endif()
33+
MESSAGE( STATUS "Link directory: ${PROJECT_SOURCE_DIR}/lib/macos/" )
34+
link_directories("${PROJECT_SOURCE_DIR}/lib/macos/")
4035
endif()
4136
include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include/")
4237

README.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# Python Extension: Barcode and QR Code SDK
2-
The project is a CPython binding to [Dynamsoft C/C++ Barcode Reader SDK](https://www.dynamsoft.com/barcode-reader/sdk-desktop-server/). 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.
2+
This project provides a CPython binding to the [Dynamsoft C/C++ Barcode Reader SDK v9.x](https://www.dynamsoft.com/barcode-reader/sdk-desktop-server/). 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.
33

4-
## About Dynamsoft Barcode Reader
5-
- [Dynamsoft C/C++ Barcode Reader SDK v9.4.0](https://www.dynamsoft.com/barcode-reader/downloads)
4+
> 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](https://pypi.org/project/dbr/) page on PyPI for more details.
5+
6+
## About Dynamsoft Python Barcode SDK
67
- Get a [30-day FREE trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr) to activate the SDK.
8+
- Install the official Python barcode SDK via `pip install dbr`.
79

10+
### Comparison Table
11+
| Feature | Unofficial Wrapper (Community) | Official Dynamsoft Python Barcode SDK |
12+
| --- | --- | --- |
13+
| Support | Community-driven, best effort | Official support from Dynamsoft |
14+
| Documentation | README only | [Comprehensive Online Documentation](https://www.dynamsoft.com/barcode-reader/programming/python/index.html) |
15+
| API Coverage | Limited | Full API coverage |
16+
|Feature Updates| May lag behind the official SDK | First to receive new features |
17+
| Compatibility | Limited testing across environments| Thoroughly tested across all supported environments|
818

919
## Supported Python Edition
1020
* Python 3.x
1121

12-
## Install Dependencies
22+
## Installation of Dependencies
23+
To show UI, you need to install the OpenCV package:
1324
```bash
1425
pip install opencv-python
1526
```
@@ -62,11 +73,11 @@ $ scanbarcode <file-name> -u 1 -l <license-key>
6273
import barcodeQrSDK
6374
6475
# set license
65-
barcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
76+
barcodeQrSDK.initLicense("LICENSE-KEY")
6677
6778
reader = barcodeQrSDK.createInstance()
6879
69-
results, elapsed_time = reader.decodeFile("test.png")
80+
results, elapsed_time = reader.decodeFile("IMAGE-FILE")
7081
for result in results:
7182
print(result.format)
7283
print(result.text)
@@ -94,7 +105,7 @@ $ scanbarcode <file-name> -u 1 -l <license-key>
94105
95106
def run():
96107
# set license
97-
barcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
108+
barcodeQrSDK.initLicense("LICENSE-KEY")
98109
99110
# initialize barcode scanner
100111
scanner = barcodeQrSDK.createInstance()
@@ -140,30 +151,30 @@ $ scanbarcode <file-name> -u 1 -l <license-key>
140151
run()
141152
```
142153
143-
![Python barcode and QR code scanner](https://camo.githubusercontent.com/4463fa22e7bb08d196623b2ff181f22c7d92f4399298c37fd5ea43b396ed5b04/68747470733a2f2f7777772e64796e616d736f66742e636f6d2f636f6465706f6f6c2f696d672f323032322f31302f707974686f6e2d6465736b746f702d626172636f64652d71722d7363616e6e65722e706e67)
154+
![Python barcode and QR code scanner](https://www.dynamsoft.com/codepool/img/2024/08/python-barcode-scanner.png)
144155
145156
146157
147158
## Methods
148-
- `barcodeQrSDK.initLicense('YOUR-LICENSE-KEY')` # set barcode SDK license globally
159+
- `barcodeQrSDK.initLicense('YOUR-LICENSE-KEY')`: Set the global license key for the barcode SDK.
149160
150161
```python
151-
barcodeQrSDK.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
162+
barcodeQrSDK.initLicense("LICENSE-KEY")
152163
```
153164
154-
- `barcodeQrSDK.createInstance()` # create a barcode reader instance
165+
- `barcodeQrSDK.createInstance()`: Create a new barcode reader instance.
155166
156167
```python
157168
reader = barcodeQrSDK.createInstance()
158169
```
159-
- `decodeFile(filename)` # decode barcode and QR code from an image file
170+
- `decodeFile(filename)`: Decode barcodes and QR codes from an image file.
160171
161172
```python
162-
results, elapsed_time = reader.decodeFile("test.png")
173+
results, elapsed_time = reader.decodeFile("IMAGE-FILE")
163174
```
164-
- `decodeMat(Mat image)` # decode barcode and QR code from Mat
175+
- `decodeMat(Mat image)`: Decode barcodes and QR codes from an OpenCV Mat.
165176
```python
166-
image = cv2.imread("test.png")
177+
image = cv2.imread("IMAGE-FILE")
167178
results = reader.decodeMat(image)
168179
for result in results:
169180
print(result.format)
@@ -178,13 +189,13 @@ $ scanbarcode <file-name> -u 1 -l <license-key>
178189
print(result.y4)
179190
```
180191
181-
- `getParameters()` # return JSON string
192+
- `getParameters()`: Retrieve the current SDK parameters as a JSON string.
182193
183194
```python
184195
params = reader.getParameters()
185196
```
186197
187-
- `setParameters(JSON string)` # set barcode SDK parameters
198+
- `setParameters(JSON string)`: Set barcode SDK parameters using a JSON string.
188199
189200
```python
190201
import json
@@ -195,42 +206,39 @@ $ scanbarcode <file-name> -u 1 -l <license-key>
195206
ret = reader.setParameters(params)
196207
```
197208
198-
- `addAsyncListener(callback function)` # start a native thread and register a Python function for receiving barcode QR code results
199-
- `decodeMatAsync(<opencv mat data>)` # decode barcode QR code from OpenCV Mat asynchronously
209+
- `addAsyncListener(callback function)`: Register a Python function to receive barcode results asynchronously.
210+
- `decodeMatAsync(<opencv mat data>)`: Asynchronously decode barcodes and QR codes from an OpenCV Mat.
200211
```python
201212
def callback(results, elapsed_time):
202213
print(results)
203214
204215
import cv2
205-
image = cv2.imread("test.png")
216+
image = cv2.imread("IMAGE-FILE")
206217
reader.addAsyncListener(callback)
207218
reader.decodeMatAsync(image)
208219
sleep(1)
209220
```
210-
- `clearAsyncListener()` # stop the native thread and clear the registered Python function
211-
- `decodeBytes(bytes, width, height, stride, imageformat)` # 0: gray; 1: rgb888
221+
- `clearAsyncListener()`: Stop the asynchronous listener and clear the registered callback.
222+
- `decodeBytes(bytes, width, height, stride, imageformat)`: Decode barcodes from a raw image byte array.
223+
212224
```python
213225
import cv2
214-
image = cv2.imread("test.png")
226+
image = cv2.imread("IMAGE-FILE")
215227
results, elapsed_time = scanner.decodeBytes(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
216228
```
217-
- `decodeBytesAsync` # decode image byte array asynchronously
229+
- `decodeBytesAsync`: Asynchronously decode image byte arrays.
218230
219231
```python
220232
def callback(results, elapsed_time):
221233
print(results)
222234
223235
import cv2
224-
image = cv2.imread("test.png")
236+
image = cv2.imread("IMAGE-FILE")
225237
imagebytes = image.tobytes()
226238
scanner.decodeBytesAsync(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
227239
sleep(1)
228240
```
229241
230-
## Online Documentation for Dynamsoft C/C++ Barcode SDK
231-
To customize Python API based on C/C++, please refer to the
232-
[online documentation](https://www.dynamsoft.com/barcode-reader/programming/c/user-guide.html?ver=latest).
233-
234242
## Supported Barcode Symbologies
235243
- Linear Barcodes (1D)
236244

camera_async_api.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import barcodeQrSDK
2+
import numpy as np
3+
import cv2
4+
import json
5+
6+
g_results = None
7+
8+
9+
def callback(results, elapsed_time):
10+
global g_results
11+
g_results = (results, elapsed_time)
12+
13+
14+
def run():
15+
# set license
16+
barcodeQrSDK.initLicense(
17+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
18+
19+
# initialize barcode scanner
20+
scanner = barcodeQrSDK.createInstance()
21+
params = scanner.getParameters()
22+
# Convert string to JSON object
23+
json_obj = json.loads(params)
24+
# json_obj['ImageParameter']['ExpectedBarcodesCount'] = 999
25+
params = json.dumps(json_obj)
26+
ret = scanner.setParameters(params)
27+
28+
scanner.addAsyncListener(callback)
29+
30+
cap = cv2.VideoCapture(0)
31+
while True:
32+
ret, image = cap.read()
33+
if image is not None:
34+
scanner.decodeMatAsync(image)
35+
36+
# scanner.decodeBytesAsync(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
37+
38+
# results, elapsed_time = scanner.decodeBytes(image.tobytes(), image.shape[1], image.shape[0], image.strides[0], barcodeQrSDK.ImagePixelFormat.IPF_BGR_888)
39+
# results, elapsed_time = scanner.decodeMat(image)
40+
# g_results = (results, elapsed_time)
41+
42+
if g_results != None:
43+
print('Elapsed time: ' + str(g_results[1]) + 'ms')
44+
cv2.putText(image, 'Elapsed time: ' + str(
45+
g_results[1]) + 'ms', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
46+
for result in g_results[0]:
47+
x1 = result.x1
48+
y1 = result.y1
49+
x2 = result.x2
50+
y2 = result.y2
51+
x3 = result.x3
52+
y3 = result.y3
53+
x4 = result.x4
54+
y4 = result.y4
55+
56+
cv2.drawContours(
57+
image, [np.int0([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2)
58+
cv2.putText(image, result.text, (x1, y1),
59+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
60+
61+
cv2.imshow('Barcode QR Code Scanner', image)
62+
ch = cv2.waitKey(1)
63+
if ch == 27:
64+
break
65+
66+
scanner.clearAsyncListener()
67+
68+
69+
if __name__ == '__main__':
70+
run()

0 commit comments

Comments
 (0)