首页 > 代码库 > python zbar

python zbar

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
wget http://iweb.dl.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2
bzip2 -d zbar-0.10.tar.bz2
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
https://github.com/npinchot/zbar
python setup.py install
 
 
 
qrcode解码例子
#!/usr/bin/pythonimport zbarfrom PIL import Imageimport urllibimport cStringIO#图片地址替换成你的qrcode图片地址URL = (http://example.qiniudn.com/msgimagepicc4WJ-4iTk8.jpeg)# create a readerscanner = zbar.ImageScanner()# configure the readerscanner.parse_config(enable)# obtain image dataimgfile = cStringIO.StringIO(urllib.urlopen(URL).read())pil = Image.open(imgfile).convert(L)width, height = pil.sizeraw = pil.tostring()# wrap image dataimage = zbar.Image(width, height, Y800, raw)# scan the image for barcodesscanner.scan(image)# extract resultsfor symbol in image:    # do something useful with results    print decoded, symbol.type, symbol, "%s" % symbol.data# clean updel(image)

 

 
 
 

python zbar