Python QR code parsing

Source: Internet
Author: User
Tags imagemagick
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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.