Skip to content

Commit

Permalink
- Update workflows
Browse files Browse the repository at this point in the history
- Add an arm32/64 example
- Add a QR code example
  • Loading branch information
yushulx committed Aug 15, 2024
1 parent d87a34c commit 7b6f9e7
Show file tree
Hide file tree
Showing 42 changed files with 936 additions and 70 deletions.
37 changes: 19 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: ['3.11', '3.12']

steps:
Expand All @@ -17,19 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: "cp39-*"
CIBW_ARCHS_LINUX: auto, aarch64
python-version: ${{ matrix.python-version }}

- name: Run test.py in develop mode
run: |
Expand All @@ -38,10 +26,6 @@ jobs:
python --version
python test.py
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
Expand All @@ -63,6 +47,23 @@ jobs:
# alternatively, to publish when a GitHub Release is created, use the following rule:
# if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: "cp39-*"
CIBW_ARCHS_LINUX: auto, aarch64


- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl

- uses: actions/download-artifact@v2
with:
name: artifact
Expand Down
5 changes: 5 additions & 0 deletions examples/official/9.x/arm32_arm64/DockerfileArm32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM arm32v7/python

RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx
RUN pip install dbr opencv-python pillow

5 changes: 5 additions & 0 deletions examples/official/9.x/arm32_arm64/DockerfileArm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM arm64v8/python

RUN apt-get update && apt-get install -y cmake libgl1-mesa-glx
RUN pip install dbr opencv-python pillow

38 changes: 38 additions & 0 deletions examples/official/9.x/arm32_arm64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Docker Images for Python Barcode Detection on ARM64 and ARM32
This repository provides a guide on how to use the Dynamsoft Barcode Reader Python SDK within Docker containers designed for ARM64 and ARM32 architectures.

## Building Docker Images for ARM64 and ARM32

To build Docker images for ARM64 and ARM32, execute the following commands:

```bash
docker run --rm --privileged multiarch/qemu-user-static:register --reset
docker build --platform linux/arm64 -f DockerfileArm64 -t <IMAGE-NAME> .
docker build --platform linux/arm/v7 -f DockerfileArm32 -t <IMAGE-NAME> .
```

## Running Python Barcode Detection in Docker Containers

To run barcode detection using the Python script inside a Docker container, use these commands:

```bash
docker run --platform linux/arm64 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp <IMAGE-NAME> python pillow_test.py
docker run --platform linux/arm/v7 -it --rm -v ${pwd}:/usr/src/myapp -w /usr/src/myapp <IMAGE-NAME> python pillow_test.py
```

**Try the Pre-built Images**

You can also try the pre-built images directly:

```bash
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
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
```

## Emulating Raspberry Pi
Use [dockerpi](https://github.com/lukechilds/dockerpi) to test the performance of the Python Barcode SDK on Raspberry Pi emulators:

```bash
docker run -it lukechilds/dockerpi pi2
docker run -it lukechilds/dockerpi pi3
```
29 changes: 29 additions & 0 deletions examples/official/9.x/arm32_arm64/capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import cv2 as cv
from dbr import *

capture = cv.VideoCapture(0)

if not capture.isOpened():
print("Cannot open camera")
exit()

BarcodeReader.init_license(
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
reader = BarcodeReader()

index = 0

while True:
frame = capture.read()[1]
cv.imshow("frame", frame)

if cv.waitKey(1) == ord('q'):
break

results = reader.decode_buffer(frame)
if results != None and len(results) > 0:
cv.imwrite('images/' + str(index) + '.png', frame)
index += 1

if index == 10:
break
50 changes: 50 additions & 0 deletions examples/official/9.x/arm32_arm64/cv_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
import os
import cv2 as cv
from dbr import *
import dbr
import time


def main():
print('version: ' + dbr.__version__)
BarcodeReader.init_license(
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")

reader = BarcodeReader()
reader.init_runtime_settings_with_file(
'faster.json', conflict_mode=EnumConflictMode.CM_OVERWRITE)

# read file list
folder = '../../../../images'
target_dir = os.path.join(os.getcwd(), folder)

if os.path.exists(target_dir):
filelist = os.listdir(target_dir)

index = 0
while index < 5:
file = filelist[index]
filapath = os.path.join(target_dir, file)

if os.path.isfile(filapath):
image = cv.imread(filapath)

start_time = time.time()
results = reader.decode_buffer(image)
elapsed_time = time.time() - start_time

print(filelist[0] + ", elapsed time: " +
str(round(elapsed_time * 1000)) + "ms, ")
if results != None:
for result in results:
print(result.barcode_format_string +
': ' + result.barcode_text)
else:
print(' results: 0')

index += 1


if __name__ == '__main__':
main()
Loading

0 comments on commit 7b6f9e7

Please sign in to comment.