跳转到主要内容

基于cffi的zbar二维码解码器的高效绑定(Py2、Py3和PyPy)

项目描述

为zbar(http://zbar.sourceforge.net/)设计的Python cffi绑定,旨在尽可能高效。

兼容Python 2、Python 3和PyPy!

注意:目前还在进行中。完全功能性和生产就绪(请参阅NumPy注意),但缺少一些配置选项。

安装

$ pip install libzbar-cffi

示例

>>> import libzbar as zb

# Images can be loaded from PIL images:
>>> from PIL import Image
>>> im = Image.open("test/qr-numeric.png")
>>> zb.Image.from_im(im).scan()
[<Symbol type=ZBAR_QRCODE quality=1 data='12345' locator=[(12, 12), (12, 75), (75, 75), (75, 12)]>]

# And from NumPy arrays. Note: if the array has an 8-bit data type (ex,
# uint8) a pointer to its data will be passed directly into zbar making
# this method very efficient.
>>> import numpy as np
>>> zb.Image.from_np(im.size, np.array(im)).scan()
[<Symbol type=ZBAR_QRCODE quality=1 data='12345' locator=[(12, 12), (12, 75), (75, 75), (75, 12)]>]

# By default, only QR codes will be scanned. Other symbol types can be
# scanned using the ``symbol_type`` argument (see ``libzbar.symbol_types``),
# or ``0`` for "all symbol types":
>>> ean13 = zb.Image.from_im(Image.open("test/ean13-example.png"))
>>> ean13.scan()
[]
>>> ean13.scan(symbol_type=0)
[<Symbol type=ZBAR_EAN13 quality=449 data='0012345678905' locator=[(30, 23), ..., (30, 247)]>]

NumPy注意

当使用Image.from_np(…)构造函数时,将指向底层数组的指针直接传递给zbar。检查数组的大小和数据类型,但目前忽略了ctypes标志,如果底层数组不是简单的uint8_t[size[0] * size[1]],可能会发生奇怪的事情。

此外,不应该Image的生命周期内更改数组,因为这可能会使数据指针无效。

项目详情


下载文件

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

源分布

libzbar-cffi-0.2.1.tar.gz (15.2 kB 查看哈希值)

上传时间: 源代码

由以下支持