zbar 解析 图片 二维码 条形码
#!/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__': url = 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTQBgBUaLLVTQ-kxAa28JDrwA9gVrD0wWNcMgUutOEYwRxlDaaWGQ' qrRead(url)