python各个平台zbar安装

36 篇文章 0 订阅
7 篇文章 0 订阅

zbar 可以解析 qrcode

不过安装过程可是艰辛

 本地开发用mac,生产服务器用ubuntu。安装方式不同。整理出以下安装方式

Ubuntu 14.04.1 LTS (GNU/Linux 3.8.0-29-generic x86_64)
$ apt-get install libzbar-dev
$ pip install zbar
 
Ubuntu 10.04.4 LTS
apt-get install libzbar-dev
apt-get install python-gtk2-dev
tar -xvf zbar-0.10.tar
./configure  --without-qt
make
make install
pip install zbar

mac
brew update && brew upgrade
brew install zbar
不要pip install zbar。而是下载这个包,修正了mac下的segmentation fault的bug
python setup.py install
 
 
qrcode解码例子
复制代码
#!/usr/bin/python
import zbar
from PIL import Image
import urllib
import cStringIO

#图片地址替换成你的qrcode图片地址
URL = ('http://example.qiniudn.com/msgimagepicc4WJ-4iTk8.jpeg')
# create a reader
scanner = zbar.ImageScanner()
# configure the reader
scanner.parse_config('enable')
# obtain image data
imgfile = cStringIO.StringIO(urllib.urlopen(URL).read())
pil = Image.open(imgfile).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)
复制代码

原文地址: http://www.cnblogs.com/yemsheng/p/4166988.html


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值