跳转到主要内容

简单的zbar包装器

项目描述

ZbarLight

zbarlight 是 zbar 库的简单包装器。目前,它可以读取所有 zbar 支持的代码。欢迎贡献、建议和pull requests。

zbarlight 在 Github 上托管于 <https://github.com/Polyconseil/zbarlight/>。

安装

在安装 zbarlight 之前,您需要安装 ZBar 条形码阅读器 <http://zbar.sourceforge.net/> 和其头文件。

在 Debian 上

$ apt-get install libzbar0 libzbar-dev
$ pip install zbarlight  # you can also use setuptools directly

在 Mac OS X 上

$ brew install zbar
$ export LDFLAGS="-L$(brew --prefix zbar)/lib"
$ export CFLAGS="-I$(brew --prefix zbar)/include"
$ pip install zbarlight

在 Windows 上

说明可以在 <https://gist.github.com/Zephor5/aea563808d80f488310869b69661f330> 上找到。

如何使用 ZbarLight

from PIL import Image
import zbarlight

file_path = './tests/fixtures/two_qr_codes.png'
with open(file_path, 'rb') as image_file:
    image = Image.open(image_file)
    image.load()

codes = zbarlight.scan_codes(['qrcode'], image)
print('QR codes: %s' % codes)

故障排除

在某些情况下,zbarlight无法在图像中检测到1D或2D条码,已知的一个原因是图像背景颜色与转换为灰度后的前景颜色相同(在具有alpha通道的图像中会发生这种情况)。您可以使用copy_image_on_background函数为您图像添加背景颜色。

from PIL import Image
import zbarlight

file_path = './tests/fixtures/two_qr_codes.png'
with open(file_path, 'rb') as image_file:
    image = Image.open(image_file)
    image.load()

new_image = zbarlight.copy_image_on_background(image, color=zbarlight.WHITE)  # <<<<<<<<<<<<<<<< Add this line <<<<
codes = zbarlight.scan_codes(['qrcode'], new_image)
print('QR codes: %s' % codes)

其他一些未知解决方案的情况显示在scan_codes()测试中(搜索预期失败)。任何关于这些情况的线索都受欢迎。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

zbarlight-3.0.tar.gz (7.1 kB 查看哈希值)

上传时间

由...