diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 00:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 00:06:44 +0000 |
commit | 44cf8ec67278bd1ab6c7f83a9993f7a5686a9541 (patch) | |
tree | 5eec4b0d1a3f163d279c3c27c03324ba49fa235a /python/examples/scan_image.py | |
parent | Initial commit. (diff) | |
download | zbar-upstream.tar.xz zbar-upstream.zip |
Adding upstream version 0.23.93.upstream/0.23.93upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/examples/scan_image.py')
-rw-r--r-- | python/examples/scan_image.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/python/examples/scan_image.py b/python/examples/scan_image.py new file mode 100644 index 0000000..e26cb42 --- /dev/null +++ b/python/examples/scan_image.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +from sys import argv +import zbar +from PIL import Image + +if len(argv) < 2: exit(1) + +# create a reader +scanner = zbar.ImageScanner() + +# configure the reader +scanner.parse_config('enable') + +# obtain image data +pil = Image.open(argv[1]).convert('L') +width, height = pil.size +raw = pil.tobytes() + +# wrap image data +image = zbar.Image(width, height, 'Y800', raw) + +# scan the image for barcodes +scanner.scan(image) + +# extract results +for symbol in image: + # do something useful with results + print('decoded', symbol.type, 'symbol', '"%s"' % symbol.data) + +# clean up +del(image) |