Skip to content

Commit c23f896

Browse files
committed
Update
1 parent 1ecc480 commit c23f896

File tree

4 files changed

+87
-58
lines changed

4 files changed

+87
-58
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [windows-latest]
12+
python-version: ['3.11', '3.12']
1213

1314
steps:
1415
- uses: actions/checkout@v2
1516

1617
- name: Set up Python
1718
uses: actions/setup-python@v4
1819
with:
19-
python-version: '3.x'
20+
python-version: ${{ matrix.python-version }}
2021

2122
- name: Set up QEMU
2223
if: runner.os == 'Linux'
@@ -29,12 +30,12 @@ jobs:
2930
env:
3031
CIBW_ARCHS_LINUX: auto, aarch64
3132

32-
# - name: Run test.py in develop mode
33-
# run: |
34-
# python setup_setuptools.py develop
35-
# python -m pip install opencv-python
36-
# python --version
37-
# python test.py
33+
- name: Run test.py in develop mode
34+
run: |
35+
python setup_setuptools.py develop
36+
python -m pip install opencv-python
37+
python --version
38+
python test.py
3839
3940
- uses: actions/upload-artifact@v2
4041
with:

examples/official/9.x/zxing_zbar/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ pip install -r requirements.txt
3030
python app.py -d <folder_directory>
3131
```
3232

33+
**ZXing**
34+
35+
![python zxing barcode detection](https://www.dynamsoft.com/codepool/img/2024/08/python-zxing-barcode-detection.png)
36+
37+
**ZBar**
38+
39+
![python zxing barcode detection](https://www.dynamsoft.com/codepool/img/2024/08/python-zbar-barcode-detection.png)
40+
41+
**Dynamsoft Barcode Reader**
42+
43+
![python zxing barcode detection](https://www.dynamsoft.com/codepool/img/2024/08/python-dbr-barcode-detection.png)
44+
3345
## Benchmark Results
3446
Below is a visual comparison of the barcode recognition rates among ZXing, ZBar, and Dynamsoft Barcode Reader based on the dataset.
3547

36-
![barcode sdk benchmark](https://www.dynamsoft.com/codepool/img/2020/02/benchmark-barcode-sdk.png)
48+
![barcode sdk benchmark](https://www.dynamsoft.com/codepool/img/2024/08/python-barcode-sdk-benchmark.png)
3749

3850
## Blog
39-
[How to Use Python ZXing and Python ZBar on Windows 10](https://www.dynamsoft.com/codepool/python-zxing-zbar-barcode.html)
51+
[Comparing Barcode Scanning in Python: ZXing vs. ZBar vs. Dynamsoft Barcode Reader](https://www.dynamsoft.com/codepool/python-zxing-zbar-barcode.html)

examples/official/9.x/zxing_zbar/app.py

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,43 @@
77
import os
88
import data
99
import cv2
10+
import numpy as np
1011

1112

1213
def zxing_decode(filename):
1314
start = time.time()
1415
img = cv2.imread(filename)
1516
zxing_results = zxingcpp.read_barcodes(img)
1617
elapsed_time = time.time() - start
17-
if zxing_results != None:
18-
for result in zxing_results:
19-
print('ZXing: {}. Elapsed time: {}ms'.format(
20-
result.text, int(elapsed_time * 1000)))
21-
return zxing_results
22-
else:
23-
print('ZXing failed to decode {}'.format(filename))
24-
25-
return None
18+
print('ZXing: Elapsed time: {}ms'.format(int(elapsed_time * 1000)))
19+
return zxing_results
2620

2721

28-
def zbar_decode(zbar_reader, filename):
22+
def zbar_decode(filename):
2923
start = time.time()
3024
zbar_results = zbar.decode(Image.open(filename))
3125
elapsed_time = time.time() - start
32-
if len(zbar_results) > 0:
33-
for zbar_result in zbar_results:
34-
print('ZBar: {}. Elapsed time: {}ms'.format(
35-
zbar_result.data.decode("utf-8"), int(elapsed_time * 1000)))
36-
37-
return zbar_results
38-
else:
39-
print('ZBar failed to decode {}'.format(filename))
40-
41-
return None
26+
print('ZBar: Elapsed time: {}ms'.format(int(elapsed_time * 1000)))
27+
return zbar_results
4228

4329

4430
def dbr_decode(dbr_reader, filename):
4531
try:
4632
start = time.time()
4733
dbr_results = dbr_reader.decode_file(filename)
4834
elapsed_time = time.time() - start
35+
print('Dynamsoft Barcode Reader: Elapsed time: {}ms'.format(
36+
int(elapsed_time * 1000)))
4937

50-
if dbr_results != None:
51-
for text_result in dbr_results:
52-
# print(textResult["BarcodeFormatString"])
53-
print('Dynamsoft Barcode Reader: {}. Elapsed time: {}ms'.format(
54-
text_result.barcode_text, int(elapsed_time * 1000)))
38+
return dbr_results
5539

56-
return dbr_results
57-
else:
58-
print("DBR failed to decode {}".format(filename))
5940
except Exception as err:
6041
print("DBR failed to decode {}".format(filename))
6142

6243
return None
6344

6445

65-
def dataset(directory=None, zbar_reader=None, dbr_reader=None):
46+
def dataset(directory=None, dbr_reader=None):
6647
if directory != None:
6748
print(directory)
6849
files = os.listdir(directory)
@@ -91,17 +72,16 @@ def dataset(directory=None, zbar_reader=None, dbr_reader=None):
9172
r3 = ''
9273

9374
# ZBar
94-
if zbar_reader != None:
95-
zbar_results = zbar_decode(zbar_reader, file_path)
96-
if zbar_results != None:
97-
for zbar_result in zbar_results:
98-
zbar_text = zbar_result.data.decode("utf-8")
99-
r1 = zbar_text
100-
if r1 == expected_result:
101-
zbar_count += 1
102-
break
103-
else:
104-
print('Fail to decode {}'.format(filename))
75+
zbar_results = zbar_decode(file_path)
76+
if zbar_results != None:
77+
for zbar_result in zbar_results:
78+
zbar_text = zbar_result.data.decode("utf-8")
79+
r1 = zbar_text
80+
if r1 == expected_result:
81+
zbar_count += 1
82+
break
83+
else:
84+
print('Fail to decode {}'.format(filename))
10585

10686
# DBR
10787
if dbr_reader != None:
@@ -137,10 +117,10 @@ def dataset(directory=None, zbar_reader=None, dbr_reader=None):
137117
r1 = 0
138118
r2 = 0
139119
r3 = 0
140-
if zbar_reader != None:
141-
zbar_rate = zbar_count * 100 / total_count
142-
r1 = '{0:.2f}%'.format(zbar_rate)
143-
print('ZBar recognition rate: {0:.2f}%'.format(zbar_rate))
120+
121+
zbar_rate = zbar_count * 100 / total_count
122+
r1 = '{0:.2f}%'.format(zbar_rate)
123+
print('ZBar recognition rate: {0:.2f}%'.format(zbar_rate))
144124

145125
if dbr_reader != None:
146126
dbr_rate = dbr_count * 100 / total_count
@@ -180,18 +160,54 @@ def main():
180160
dbr_reader = BarcodeReader()
181161

182162
if image != None:
163+
img = cv2.imread(image)
164+
copy = img.copy()
183165
# ZXing
184-
zxing_decode(image)
166+
zxing_results = zxing_decode(image)
167+
if zxing_results != None:
168+
for result in zxing_results:
169+
print('ZXing: {}. '.format(
170+
result.text))
171+
172+
cv2.drawContours(
173+
img, [np.intp([(result.position.top_left.x, result.position.top_left.y), (result.position.top_right.x, result.position.top_right.y), (result.position.bottom_right.x, result.position.bottom_right.y), (result.position.bottom_left.x, result.position.bottom_left.y)
174+
])], 0, (0, 255, 0), 2)
175+
176+
cv2.imshow('ZXing', img)
185177

186178
# ZBar
187-
zbar_decode(zbar, image)
179+
img = copy.copy()
180+
zbar_results = zbar_decode(image)
181+
182+
if len(zbar_results) > 0:
183+
for zbar_result in zbar_results:
184+
print('ZBar: {}. '.format(
185+
zbar_result.data.decode("utf-8")))
186+
187+
cv2.drawContours(
188+
img, [np.intp([zbar_result.polygon[0], zbar_result.polygon[1], zbar_result.polygon[2], zbar_result.polygon[3]
189+
])], 0, (0, 255, 0), 2)
190+
191+
cv2.imshow('zbar', img)
188192

189193
# Dynamsoft Barcode Reader
190-
dbr_decode(dbr_reader, image)
194+
img = copy.copy()
195+
dbr_results = dbr_decode(dbr_reader, image)
196+
if dbr_results != None:
197+
for text_result in dbr_results:
198+
print('Dynamsoft Barcode Reader: {}'.format(
199+
text_result.barcode_text))
200+
201+
points = text_result.localization_result.localization_points
202+
cv2.drawContours(
203+
img, [np.intp([points[0], points[1], points[2], points[3]])], 0, (0, 255, 0), 2)
204+
205+
cv2.imshow('DBR', img)
206+
207+
cv2.waitKey(0)
191208

192209
if directory != None:
193-
dataset(directory,
194-
zbar_reader=zbar, dbr_reader=dbr_reader)
210+
dataset(directory, dbr_reader=dbr_reader)
195211

196212

197213
if __name__ == "__main__":
Binary file not shown.

0 commit comments

Comments
 (0)