Skip to content

Instantly share code, notes, and snippets.

@stefanfoulis
Created August 5, 2011 16:57
Show Gist options
  • Save stefanfoulis/1127976 to your computer and use it in GitHub Desktop.
Save stefanfoulis/1127976 to your computer and use it in GitHub Desktop.
zbar fun
#-*- 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