summaryrefslogtreecommitdiffstats
path: root/python/examples/scan_image.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/examples/scan_image.py')
-rw-r--r--python/examples/scan_image.py31
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)