File: scan_image.py

package info (click to toggle)
zbar 0.10%2Bdoc-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,856 kB
  • ctags: 2,903
  • sloc: ansic: 21,641; sh: 10,745; cpp: 1,997; python: 774; xml: 473; perl: 289; makefile: 189
file content (31 lines) | stat: -rwxr-xr-x 585 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
from sys import argv
import zbar
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.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

# clean up
del(image)