Home > Backend Development > Python Tutorial > zbar解码二维码和条形码示例

zbar解码二维码和条形码示例

WBOY
Release: 2016-06-16 08:45:21
Original
1800 people have browsed it

复制代码 代码如下:

#!/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, '图片内容为:\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)


要安装 python-zbar 

检查启用了 universe 存储库。
检查 /etc/apt/sources.list 与 sudo,以确保您具有正确的权限使用您最喜爱的编辑器。
 
复制代码 代码如下:

sudo gedit /etc/apt/sources.list
 
确保包含 universe。

在发生任何更改后,您应该运行此命令以更新您的系统。
复制代码 代码如下:

sudo apt-get update

你现在可以安装这样的包。

安装 python-zbar
复制代码 代码如下:

sudo apt-get install python-zbar

这将安装 python-zbar 和它所依赖的任何其他包。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template