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.