zbar-windows/python/examples/scan_image.py
Mauro Carvalho Chehab c06e7e1940 python: Make it work with modern versions of python 2
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>
2018-08-07 16:12:54 -03:00

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)