Zbar decoding QR code and bar code example

Source: Internet
Author: User
This article mainly introduces the zbar decoding QR code and bar code examples. For more information, see The 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
Resize = zbar. imageresize ()

# Configure the reader
Parser. 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
Scan. scan (image)

Tmpdata =''
# Extract results
For symbol in image:
# Do something useful with results
Print symbol. type, 'image 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)



Install python-zbar

Check that the universe repository is enabled.
Check/etc/apt/sources. list and sudo to ensure that you have the right permissions to use your favorite editor.

The code is as follows:


Sudo gedit/etc/apt/sources. list


Ensure that universe is included.

After any changes, you should run this command to update your system.

The code is as follows:


Sudo apt-get update


You can install such a package now.

Install python-zbar

The code is as follows:


Sudo apt-get install python-zbar


This will install python-zbar and any other packages it depends 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.