简单的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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6f703ac04ec4f700db02dc948835ca73176b52854ddcfe267ac62954e34aacec |
|
MD5 | d7c07cbed25d40955f5f3560be642843 |
|
BLAKE2b-256 | fa45be440a16351d1a556a5012489cef30781001f59a01fc8b5d549bfbd624ad |