Python parses the QR code because it needs to parse the QR code image. the operating environment is centos7.2 and python version is 2.7.5. since zbar only supports Python2.6, you are prepared to use the source code compilation and installation method. The procedure is as follows:
1. install the dependency package
yum install pdftk ImageMagick ImageMagick-devel ghostscript Python-imaging python-devel
2. download the source package in the http://zbar.sourceforge.NET/download.html
3. decompression method:
tar -jxvf zbar-0.10.tar.bz2
4. Compile
./configure --without-gtk --without-qt --disable-video --prefix=/usr/local
5. Installation
make && make install
6, download zbar source code, and install, https://pypi.python.org/pypi/zbar/0.10
7. decompress the tar package
tar -zxvf zbar-0.10.tar.gz
8. Installation
python setup.py install
10. check whether the zbar package is successfully installed. If no error is reported, the installation is successful.
11. test zbar to parse the QR code image.
#-*-Coding: UTF-8-*-import zbarfrom PIL import Image # create an Image scan object watermark = zbar. imageworkflow () # set the object property lifecycle. parse_config ('enable') # open the Image img = Image containing the QR code. open ('
<你的图片路径>
'). Convert ('L') # obtain the image size width, height = img. size # Create a zbar image object and scan and convert it to Byte Information qrCode = zbar. image (width, height, 'y800', img. tobytes () bytes. scan (qrCode) data = ''for s in qrCode: data + = s. data # delete the image object del img # output the decoded result print data