Zbar decoding QR codes and barcode examples

Source: Internet
Author: User
Copy CodeThe code is as follows:


#!/usr/bin/env python
# coding:u8
Import OS
Import Zbar
Import Image
Import Urllib
Import UUID
def qrread (URL):

UUID1 = UUID.UUID1 ()
Filename=str (UUID1) + ". jpg"
Print Uuid1
Urllib.urlretrieve (URL, filename)

# Create a Reader
Scanner = Zbar. Imagescanner ()

# Configure the Reader
Scanner.parse_config (' Enable ')

# Obtain image data
PIL = image.open (filename). Convert (' L ')
width, height = pil.size
#pil. Show ()
Raw = Pil.tostring ()

# Wrap Image Data
Image = Zbar. Image (width, height, ' Y800 ', raw)

# Scan the image for barcodes
Scanner.scan (image)

Tmpdata= "
# Extract Results
For symbol in Image:
# do something useful with results
Print Symbol.type, ' picture content: \n%s '% symbol.data
Tmpdata=tmpdata+symbol.data


# Clean up
Del (image)
Os.remove (filename)
Return Tmpdata
if __name__ = = ' __main__ ':
url = ' Http://www.jb51.net '
Qrread (URL)



To install Python-zbar

Check that the Universe repository is enabled.
Check/etc/apt/sources.list with sudo to make sure you have the correct permissions to use your favorite editor.
Copy CodeThe code is as follows:


sudo gedit/etc/apt/sources.list


Make sure to include universe.

After any changes have occurred, you should run this command to update your system.
Copy CodeThe code is as follows:


sudo apt-get update


You can now install such a package.

Installing Python-zbar
Copy CodeThe code is as follows:


sudo apt-get install Python-zbar


This installs the Python-zbar and any other packages it relies on.
  • Related Article

    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.