Since the QR code image needs to be parsed, the operating environment is centos7.2 and the python version is 2.7.5. Since zbar only supports Python2.6, we are going to use source code compilation and installation. The specific steps are as follows:
1. Install the dependency package
yum install pdftk ImageMagick ImageMagick-devel ghostscript Python-imaging python-devel
2. Download the source code package at http://zbar.sourceforge.NET/download.html
3. The decompression method is:
tar -jxvf zbar-0.10.tar.bz2
4. Compile
./configure --without-gtk --without-qt --disable-video --prefix=/usr/local
5. Install
make && make install
6. Download the zbar source code and install it. The download address is https://pypi.python.org/pypi/zbar/0.10
7. Unzip the tar package
tar -zxvf zbar-0.10.tar.gz
8. Install
python setup.py install
10. Determine whether the zbar package is installed successfully. If no error is reported, the installation is successful
11. Test zbar to parse the QR code image
# -*- coding:utf-8 -*- import zbar from PIL import Image # 创建图片扫描对象 scanner = zbar.ImageScanner() # 设置对象属性 scanner.parse_config('enable') # 打开含有二维码的图片 img = Image.open('<你的图片路径>').convert('L') #获取图片的尺寸 width, height = img.size #建立zbar图片对象并扫描转换为字节信息 qrCode = zbar.Image(width, height, 'Y800', img.tobytes()) scanner.scan(qrCode) data = '' for s in qrCode: data += s.data # 删除图片对象 del img # 输出解码结果 print data