zbar-windows/python/examples/processor.py
Mauro Carvalho Chehab cd5b63e5b5 Update to the very latest version of zbar
zbar was using a 2010 snapshot of its hg tree.
Take a new snapshot to get zbar's improvements.

[Imported from Fedora 26 tree]
2017-03-25 23:04:38 -03:00

36 lines
729 B
Python

#!/usr/bin/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, e:
pass