Some of the examples and test code don't work with python 2.7 and PIL. Modernize them by running 2to3 and fixing PIL manually. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
32 lines
598 B
Python
32 lines
598 B
Python
#!/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)
|