Python parsing two-dimensional code

Source: Internet
Author: User
Due to the need to parse the two-dimensional code image, the operating environment is Centos7.2,python version is 2.7.5, because Zbar only support to Python2.6, so prepare to use the source code compiled installation method. The steps are as follows:

1. Install dependent packages

Yum install pdftk ImageMagick imagemagick-devel Ghostscript python-imaging python-devel

2. Download the source package in http://zbar.sourceforge.NET/download.html

3, the Decompression method is:

Tar   -jxvf    zbar-0.10.tar.bz2

4, to compile

./configure--WITHOUT-GTK--WITHOUT-QT--disable-video--prefix=/usr/local

5. Installation

Make && make install

6, download Zbar source code, and install, download address https://pypi.python.org/pypi/zbar/0.10

7. Unzip the TAR package

TAR-ZXVF zbar-0.10.tar.gz

8. Installation

Python setup.py  Install

10, determine whether the Zbar package is installed successfully, if there is no error, that is, installation success


11, Test Zbar parsing two-dimensional code image

#-*-Coding:utf-8-*-import zbarfrom PIL import image# Create picture Scan object scanner = Zbar. Imagescanner () # Set object Properties Scanner.parse_config (' Enable ') # Open the picture containing the QR code img = Image.open (' < your picture path > '). Convert (' L ') # To get the size of the picture width, height = img.size# Create Zbar Picture object and Scan to convert to byte information QRCode = Zbar. Image (width, height, ' Y800 ', Img.tobytes ()) Scanner.scan (qrcode) data = "for S" QRCode:    data + = s.data# Delete Picture Object del img # Output decoding 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.