Created
August 5, 2011 16:57
-
-
Save stefanfoulis/1127976 to your computer and use it in GitHub Desktop.
zbar fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
import zbar | |
from PIL import Image | |
def read_barcode(path): | |
scanner = zbar.ImageScanner() | |
scanner.parse_config('enable') | |
pil = Image.open(image).convert('L') | |
width, height = pil.size | |
raw = pil.tostring() | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment