Zbar decoding two-dimensional Code and barcode sample _python

Source: Internet
Author: User
Tags uuid

Copy Code code 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 and sudo to make sure you have the correct permissions to use your favorite editor.
Copy Code code as follows:

sudo gedit/etc/apt/sources.list

Ensure that universe is included.

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

sudo apt-get update

You can now install such a package.

Install Python-zbar
Copy Code code as follows:

sudo apt-get install Python-zbar

This will install Python-zbar and any other packages it relies on.

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.