一个简单的zbar包装器
zbarlight的Python项目详细描述
zBarlight
zbarlight是zbar库的简单包装器。目前,它可以读取所有zbar支持的代码。贡献, 欢迎提出建议和请求。
zbarlight与python 2和python 3兼容。
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 $exportLDFLAGS="-L$(brew --prefix zbar)/lib"$exportCFLAGS="-I$(brew --prefix zbar)/include"$ pip install zbarlight
在Windows上
指令可以在<;https://gist.github.com/Zephor5/aea563808d80f488310869b69661f330>;上找到。
如何使用zbarlight
fromPILimportImageimportzbarlightfile_path='./tests/fixtures/two_qr_codes.png'withopen(file_path,'rb')asimage_file:image=Image.open(image_file)image.load()codes=zbarlight.scan_codes(['qrcode'],image)print('QR codes: %s'%codes)
故障排除
在某些情况下,zbarlight将无法检测图像中的1d或2d代码,其中一个已知原因是 图像背景颜色与转换为灰度后的前景颜色相同(发生在 阿尔法通道)。可以使用copy_image_on_background函数在图像上添加背景色。
fromPILimportImageimportzbarlightfile_path='./tests/fixtures/two_qr_codes.png'withopen(file_path,'rb')asimage_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()测试(搜索预期的失败)中显示了一些没有已知解决方案的其他情况。任何 这些案件的线索值得欢迎。