基于cffi的zbar qr解码器有效绑定(py2、py3和pypy)
libzbar-cffi的Python项目详细描述
基于python cffi的zbar(http://zbar.sourceforge.net/)绑定设计为 尽可能有效率。
python 2、python 3和pypy兼容!
注:目前正在进行中。全功能,生产就绪 (请参见NumPy note),但缺少一些配置选项。
安装
$ 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)]>]
纽米音符
使用Image.from_np(…)构造函数时,指向基础 数组直接传递给zbar。数组的大小和数据类型是正常的 已经检查过了,但是现在ctypes flags被忽略了,所以奇怪的事情 如果欠叶数组不是直接的 uint8[size[0]*size[1]。
此外,在 Image,因为这可能使数据指针失效。