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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 |
#!/usr/bin/env python # coding: u8 import
os import
zbar import
Image import
urllib import
uuid def qrRead(url): uuid1 =
uuid.uuid1() filename = str (uuid1) + ".jpg" print
uuid1 urllib.urlretrieve(url, filename) # create a reader scanner =
zbar.ImageScanner() # configure the reader scanner.parse_config( ‘enable‘ ) # obtain image data pil =
Image. open (filename).convert( ‘L‘ ) width, height =
pil.size #pil.show() raw =
pil.tostring() # wrap image data image =
zbar.Image(width, height, ‘Y800‘ , raw) # scan the image for barcodes scanner.scan(image) tmpdata = ‘‘ # extract results for
symbol in
image: # do something useful with results print
symbol. type , ‘图片内容为:\n%s‘
% symbol.data tmpdata = tmpdata + symbol.data # clean up del (image) os.remove(filename) return
tmpdata if __name__ = =
‘__main__‘ : qrRead(url) |
原文:http://www.cnblogs.com/zihuxinyu/p/3540591.html