-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsample_read_barcodes.py
More file actions
53 lines (42 loc) · 1.63 KB
/
sample_read_barcodes.py
File metadata and controls
53 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import zivid
from zivid.experimental.toolbox.barcode import BarcodeDetector, LinearBarcodeFormat, MatrixBarcodeFormat
def _main():
app = zivid.Application()
linear_barcode_formats = {
LinearBarcodeFormat.code128,
LinearBarcodeFormat.code93,
LinearBarcodeFormat.code39,
LinearBarcodeFormat.ean13,
LinearBarcodeFormat.ean8,
LinearBarcodeFormat.upcA,
LinearBarcodeFormat.upcE,
}
matrix_barcode_formats = {
MatrixBarcodeFormat.qrcode,
MatrixBarcodeFormat.dataMatrix,
}
with app.connect_camera() as camera, BarcodeDetector() as detector:
settings2d = detector.suggest_settings(camera)
while True:
print("-" * 70)
print("Capturing frame. Press Ctrl-C to stop.")
with camera.capture(settings2d) as frame2d:
# Read linear codes
all_results_linear = detector.read_linear_codes(
frame2d,
format_filter=linear_barcode_formats,
)
# Read matrix codes
all_results_matrix = detector.read_matrix_codes(
frame2d,
format_filter=matrix_barcode_formats,
)
# Print results
print(f"Found {len(all_results_linear)} linear codes")
for result in all_results_linear:
print(f" -{result}")
print(f"Found {len(all_results_matrix)} matrix codes")
for result in all_results_matrix:
print(f" -{result}")
if __name__ == "__main__":
_main()