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:
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.