zbar解码二维码和条形码示例
#!/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 和它所依赖的任何其他包。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...
