Skip to content

Commit f39cd49

Browse files
committed
Docker for ARM environments
1 parent 6ab2ae6 commit f39cd49

8 files changed

Lines changed: 289 additions & 0 deletions

File tree

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 dynamsoft-barcode-reader-bundle 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 dynamsoft-barcode-reader-bundle opencv-python pillow
5+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
```
39+
40+
## Blog
41+
[A Guide to Running ARM32 and ARM64 Python Barcode Readers in Docker Containers](https://www.dynamsoft.com/codepool/docker-arm64-arm32-python-barcode-qr-recognition.html)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import cv2
2+
from dynamsoft_capture_vision_bundle import *
3+
import numpy as np
4+
capture = cv2.VideoCapture(0)
5+
6+
if not capture.isOpened():
7+
print("Cannot open camera")
8+
exit()
9+
10+
error_code, error_message = LicenseManager.init_license(
11+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
12+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
13+
print("License initialization failed: ErrorCode:",
14+
error_code, ", ErrorString:", error_message)
15+
else:
16+
cvr_instance = CaptureVisionRouter()
17+
index = 0
18+
while True:
19+
ret, frame = capture.read()
20+
21+
if cv2.waitKey(1) == ord('q'):
22+
break
23+
24+
result = cvr_instance.capture(
25+
frame, EnumPresetTemplate.PT_READ_BARCODES.value)
26+
27+
if result.get_error_code() != EnumErrorCode.EC_OK:
28+
print("Error:", result.get_error_code(),
29+
result.get_error_string())
30+
else:
31+
items = result.get_items()
32+
print('Found {} barcodes.'.format(len(items)))
33+
for item in items:
34+
format_type = item.get_format_string()
35+
text = item.get_text()
36+
print("Barcode Format:", format_type)
37+
print("Barcode Text:", text)
38+
39+
location = item.get_location()
40+
x1 = location.points[0].x
41+
y1 = location.points[0].y
42+
x2 = location.points[1].x
43+
y2 = location.points[1].y
44+
x3 = location.points[2].x
45+
y3 = location.points[2].y
46+
x4 = location.points[3].x
47+
y4 = location.points[3].y
48+
print("Location Points:")
49+
print("({}, {})".format(x1, y1))
50+
print("({}, {})".format(x2, y2))
51+
print("({}, {})".format(x3, y3))
52+
print("({}, {})".format(x4, y4))
53+
print("-------------------------------------------------")
54+
55+
pts = np.array([(x1, y1), (x2, y2), (x3, y3), (x4, y4)], np.int32)
56+
pts = pts.reshape((-1, 1, 2))
57+
cv2.drawContours(frame, [pts], 0, (0, 255, 0), 2)
58+
59+
cv2.putText(frame, text, (x1, y1 - 10),
60+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
61+
62+
cv2.imshow(
63+
"Original Image with Detected Barcodes", frame)
64+
65+
cv2.destroyAllWindows()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import cv2 as cv
4+
from dynamsoft_capture_vision_bundle import *
5+
import time
6+
7+
8+
def main():
9+
10+
error_code, error_message = LicenseManager.init_license(
11+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
12+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
13+
print("License initialization failed: ErrorCode:",
14+
error_code, ", ErrorString:", error_message)
15+
16+
# read file list
17+
folder = '../../../images'
18+
target_dir = os.path.join(os.getcwd(), folder)
19+
cvr_instance = CaptureVisionRouter()
20+
if os.path.exists(target_dir):
21+
filelist = os.listdir(target_dir)
22+
23+
index = 0
24+
while index < 3:
25+
file = filelist[index]
26+
filapath = os.path.join(target_dir, file)
27+
28+
if os.path.isfile(filapath):
29+
image = cv.imread(filapath)
30+
31+
start_time = time.time()
32+
result = cvr_instance.capture(image, EnumPresetTemplate.PT_READ_BARCODES.value)
33+
elapsed_time = time.time() - start_time
34+
35+
print(filelist[index] + ", elapsed time: " +
36+
str(round(elapsed_time * 1000)) + "ms, ")
37+
if result.get_error_code() != EnumErrorCode.EC_OK:
38+
print("Error:", result.get_error_code(),
39+
result.get_error_string())
40+
else:
41+
items = result.get_items()
42+
print('Found {} barcodes.'.format(len(items)))
43+
for item in items:
44+
format_type = item.get_format_string()
45+
text = item.get_text()
46+
print("Barcode Format:", format_type)
47+
print("Barcode Text:", text)
48+
49+
50+
print("-------------------------------------------------")
51+
52+
index += 1
53+
54+
if __name__ == '__main__':
55+
main()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
import os
3+
from dynamsoft_capture_vision_bundle import *
4+
import time
5+
6+
7+
def main():
8+
error_code, error_message = LicenseManager.init_license(
9+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
10+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
11+
print("License initialization failed: ErrorCode:",
12+
error_code, ", ErrorString:", error_message)
13+
14+
# read file list
15+
folder = '../../../images'
16+
target_dir = os.path.join(os.getcwd(), folder)
17+
cvr_instance = CaptureVisionRouter()
18+
if os.path.exists(target_dir):
19+
filelist = os.listdir(target_dir)
20+
21+
index = 0
22+
while index < 3:
23+
file = filelist[index]
24+
filapath = os.path.join(target_dir, file)
25+
26+
if os.path.isfile(filapath):
27+
start_time = time.time()
28+
result = cvr_instance.capture(filapath, EnumPresetTemplate.PT_READ_BARCODES.value)
29+
elapsed_time = time.time() - start_time
30+
31+
print(file + ", elapsed time: " +
32+
str(round(elapsed_time * 1000)) + "ms, ")
33+
if result.get_error_code() != EnumErrorCode.EC_OK:
34+
print("Error:", result.get_error_code(),
35+
result.get_error_string())
36+
else:
37+
items = result.get_items()
38+
print('Found {} barcodes.'.format(len(items)))
39+
for item in items:
40+
format_type = item.get_format_string()
41+
text = item.get_text()
42+
print("Barcode Format:", format_type)
43+
print("Barcode Text:", text)
44+
45+
46+
print("-------------------------------------------------")
47+
48+
index += 1
49+
50+
51+
if __name__ == '__main__':
52+
main()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import time
4+
from PIL import Image
5+
from dynamsoft_capture_vision_bundle import *
6+
import numpy as np
7+
def main():
8+
error_code, error_message = LicenseManager.init_license(
9+
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
10+
if error_code != EnumErrorCode.EC_OK and error_code != EnumErrorCode.EC_LICENSE_CACHE_USED:
11+
print("License initialization failed: ErrorCode:",
12+
error_code, ", ErrorString:", error_message)
13+
14+
# read file list
15+
folder = '../../../images'
16+
target_dir = os.path.join(os.getcwd(), folder)
17+
print(target_dir)
18+
cvr_instance = CaptureVisionRouter()
19+
20+
if os.path.exists(target_dir):
21+
filelist = os.listdir(target_dir)
22+
23+
index = 0
24+
while index < len(filelist):
25+
file = filelist[index]
26+
filapath = os.path.join(target_dir, file)
27+
28+
index += 1
29+
30+
if os.path.isfile(filapath):
31+
32+
with Image.open(filapath) as im:
33+
try:
34+
start_time = time.time()
35+
img_array = np.array(im)
36+
result = cvr_instance.capture(img_array, EnumPresetTemplate.PT_READ_BARCODES.value)
37+
elapsed_time = time.time() - start_time
38+
print(file + ", elapsed time: " + str(round(elapsed_time *
39+
1000)) + "ms, " + ' results: ' + str(len(result.get_items())))
40+
41+
if result.get_error_code() != EnumErrorCode.EC_OK:
42+
print("Error:", result.get_error_code(),
43+
result.get_error_string())
44+
else:
45+
items = result.get_items()
46+
print('Found {} barcodes.'.format(len(items)))
47+
for item in items:
48+
format_type = item.get_format_string()
49+
text = item.get_text()
50+
print("Barcode Format:", format_type)
51+
print("Barcode Text:", text)
52+
53+
54+
print("-------------------------------------------------")
55+
56+
except Exception as err:
57+
print(err)
58+
59+
print('-------------------------------------')
60+
61+
62+
if __name__ == '__main__':
63+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dynamsoft-barcode-reader-bundle
2+
opencv-python
3+
pillow

0 commit comments

Comments
 (0)