diff options
Diffstat (limited to 'python/examples/processor.py')
-rw-r--r-- | python/examples/processor.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/python/examples/processor.py b/python/examples/processor.py new file mode 100644 index 0000000..b8f20f0 --- /dev/null +++ b/python/examples/processor.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +from sys import argv +import zbar + +# create a Processor +proc = zbar.Processor() + +# configure the Processor +proc.parse_config('enable') + +# initialize the Processor +device = '/dev/video0' +if len(argv) > 1: + device = argv[1] +proc.init(device) + +# setup a callback +def my_handler(proc, image, closure): + # extract results + for symbol in image.symbols: + # do something useful with results + print('decoded', symbol.type, 'symbol', '"%s"' % symbol.data) + +proc.set_data_handler(my_handler) + +# enable the preview window +proc.visible = True + +# initiate scanning +proc.active = True +try: + # keep scanning until user provides key/mouse input + proc.user_wait() +except zbar.WindowClosed as e: + pass |