Skip to content

Commit 7b6f9e7

Browse files
committed
- Update workflows
- Add an arm32/64 example - Add a QR code example
1 parent d87a34c commit 7b6f9e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+936
-70
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
os: [windows-latest]
11+
os: [windows-latest, ubuntu-latest, macos-latest]
1212
python-version: ['3.11', '3.12']
1313

1414
steps:
@@ -17,19 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v4
1919
with:
20-
python-version: ${{ matrix.python-version }}
21-
22-
- name: Set up QEMU
23-
if: runner.os == 'Linux'
24-
uses: docker/setup-qemu-action@v2
25-
with:
26-
platforms: all
27-
28-
- name: Build wheels
29-
uses: pypa/cibuildwheel@v2.6.1
30-
env:
31-
CIBW_BUILD: "cp39-*"
32-
CIBW_ARCHS_LINUX: auto, aarch64
20+
python-version: ${{ matrix.python-version }}
3321

3422
- name: Run test.py in develop mode
3523
run: |
@@ -38,10 +26,6 @@ jobs:
3826
python --version
3927
python test.py
4028
41-
- uses: actions/upload-artifact@v2
42-
with:
43-
path: ./wheelhouse/*.whl
44-
4529
build_sdist:
4630
name: Build source distribution
4731
runs-on: ubuntu-latest
@@ -63,6 +47,23 @@ jobs:
6347
# alternatively, to publish when a GitHub Release is created, use the following rule:
6448
# if: github.event_name == 'release' && github.event.action == 'published'
6549
steps:
50+
- name: Set up QEMU
51+
if: runner.os == 'Linux'
52+
uses: docker/setup-qemu-action@v2
53+
with:
54+
platforms: all
55+
56+
- name: Build wheels
57+
uses: pypa/cibuildwheel@v2.6.1
58+
env:
59+
CIBW_BUILD: "cp39-*"
60+
CIBW_ARCHS_LINUX: auto, aarch64
61+
62+
63+
- uses: actions/upload-artifact@v2
64+
with:
65+
path: ./wheelhouse/*.whl
66+
6667
- uses: actions/download-artifact@v2
6768
with:
6869
name: artifact
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM arm32v7/python
2+
3+
RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx
4+
RUN pip install dbr opencv-python pillow
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM arm64v8/python
2+
3+
RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx
4+
RUN pip install dbr opencv-python pillow
5+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Docker Images for Python Barcode Detection on ARM64 and ARM32
2+
This repository provides a guide on how to use the Dynamsoft Barcode Reader Python SDK within Docker containers designed for ARM64 and ARM32 architectures.
3+
4+
## Building Docker Images for ARM64 and ARM32
5+
6+
To build Docker images for ARM64 and ARM32, execute the following commands:
7+
8+
```bash
9+
docker run --rm --privileged multiarch/qemu-user-static:register --reset
10+
docker build --platform linux/arm64 -f DockerfileArm64 -t <IMAGE-NAME> .
11+
docker build --platform linux/arm/v7 -f DockerfileArm32 -t <IMAGE-NAME> .
12+
```
13+
14+
## Running Python Barcode Detection in Docker Containers
15+
16+
To run barcode detection using the Python script inside a Docker container, use these commands:
17+
18+
```bash
19+
docker run --platform linux/arm64 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp <IMAGE-NAME> python pillow_test.py
20+
docker run --platform linux/arm/v7 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp <IMAGE-NAME> python pillow_test.py
21+
```
22+
23+
**Try the Pre-built Images**
24+
25+
You can also try the pre-built images directly:
26+
27+
```bash
28+
docker run --platform linux/arm64 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp yushulx/dbr-arm64:1.0 python pillow_test.py
29+
docker run --platform linux/arm/v7 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp yushulx/dbr-arm32:1.0 python pillow_test.py
30+
```
31+
32+
## Emulating Raspberry Pi
33+
Use [dockerpi](https://github.com/lukechilds/dockerpi) to test the performance of the Python Barcode SDK on Raspberry Pi emulators:
34+
35+
```bash
36+
docker run -it lukechilds/dockerpi pi2
37+
docker run -it lukechilds/dockerpi pi3
38+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import cv2 as cv
2+
from dbr import *
3+
4+
capture = cv.VideoCapture(0)
5+
6+
if not capture.isOpened():
7+
print("Cannot open camera")
8+
exit()
9+
10+
BarcodeReader.init_license(
11+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
12+
reader = BarcodeReader()
13+
14+
index = 0
15+
16+
while True:
17+
frame = capture.read()[1]
18+
cv.imshow("frame", frame)
19+
20+
if cv.waitKey(1) == ord('q'):
21+
break
22+
23+
results = reader.decode_buffer(frame)
24+
if results != None and len(results) > 0:
25+
cv.imwrite('images/' + str(index) + '.png', frame)
26+
index += 1
27+
28+
if index == 10:
29+
break
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import cv2 as cv
4+
from dbr import *
5+
import dbr
6+
import time
7+
8+
9+
def main():
10+
print('version: ' + dbr.__version__)
11+
BarcodeReader.init_license(
12+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
13+
14+
reader = BarcodeReader()
15+
reader.init_runtime_settings_with_file(
16+
'faster.json', conflict_mode=EnumConflictMode.CM_OVERWRITE)
17+
18+
# read file list
19+
folder = '../../../../images'
20+
target_dir = os.path.join(os.getcwd(), folder)
21+
22+
if os.path.exists(target_dir):
23+
filelist = os.listdir(target_dir)
24+
25+
index = 0
26+
while index < 5:
27+
file = filelist[index]
28+
filapath = os.path.join(target_dir, file)
29+
30+
if os.path.isfile(filapath):
31+
image = cv.imread(filapath)
32+
33+
start_time = time.time()
34+
results = reader.decode_buffer(image)
35+
elapsed_time = time.time() - start_time
36+
37+
print(filelist[0] + ", elapsed time: " +
38+
str(round(elapsed_time * 1000)) + "ms, ")
39+
if results != None:
40+
for result in results:
41+
print(result.barcode_format_string +
42+
': ' + result.barcode_text)
43+
else:
44+
print(' results: 0')
45+
46+
index += 1
47+
48+
49+
if __name__ == '__main__':
50+
main()

0 commit comments

Comments
 (0)