Skip to main content

A ctypes-based wrapper around the zbar barcode reader.

Project description

Python Versions PyPI version Travis status Coverage Status

A ctypes-based Python wrapper around the zbar barcode reader.

The zbar wrapper is stuck in Python 2.x-land. The zbarlight wrapper doesn’t provide support for Windows and depends upon Pillow. This ctypes-based wrapper brings zbar to Python 2.7 and to Python 3.4 or greater.

Installation

The zbar DLLs are included with the Windows Python wheels. On other operating systems, you will need to install the zbar shared library.

On Mac OS X:

brew install zbar

On Linux:

sudo apt-get install libzbar0

Install this Python wrapper; use the second form to install dependencies of the command-line scripts:

pip install pyzbar
pip install pyzbar[scripts]

Example usage

The decode function accepts instances of PIL.Image.

>>> from pyzbar.pyzbar import decode
>>> from PIL import Image
>>> decode(Image.open('pyzbar/tests/code128.png'))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

It also accepts instances of numpy.ndarray, which might come from loading images using OpenCV.

>>> import cv2
>>> decode(cv2.imread('pyzbar/tests/code128.png'))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

You can also provide a tuple (pixels, width, height), where the image data is eight bits-per-pixel.

>>> image = cv2.imread('pyzbar/tests/code128.png')
>>> height, width = image.shape[:2]
>>> # Considering just the blue channel
>>> decode((image[:, :, 0].astype('uint8').tobytes(), width, height))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

>>> # Converting to greyscale
>>> grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
>>> decode((grey.tobytes(), width, height))
[Decoded(data=b'Foramenifera', type='CODE128'),
 Decoded(data=b'Rana temporaria', type='CODE128')]

License

pyzbar is distributed under the MIT license (see LICENCE.txt). The zbar shared library is distributed under the GNU Lesser General Public License, version 2.1 (see zbar-LICENCE.txt).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyzbar-0.1.0-py2.py3-none-win_amd64.whl (797.1 kB view details)

Uploaded Python 2Python 3Windows x86-64

pyzbar-0.1.0-py2.py3-none-win32.whl (829.9 kB view details)

Uploaded Python 2Python 3Windows x86

pyzbar-0.1.0-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyzbar-0.1.0-py2.py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for pyzbar-0.1.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 89034245f748ebdd68a4dee0bd3595b200c7742f8a580875206ffb532806c9f8
MD5 8821f71bace1c5ed49acea665c59aeda
BLAKE2b-256 fb9786c5aaacfb434d5b2b22379c00f70547b8257c32af54bba5278e076f22e1

See more details on using hashes here.

File details

Details for the file pyzbar-0.1.0-py2.py3-none-win32.whl.

File metadata

File hashes

Hashes for pyzbar-0.1.0-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 94589747620739e3eb04af45e73be2583929080c4c72eea4630a54d5f5d31422
MD5 8405f32e274c0518360b0d2c4fa98400
BLAKE2b-256 c47e43d45291b03e1f7b55a5ef703e7893e18853a1ebe1723323b788bfd2f33c

See more details on using hashes here.

File details

Details for the file pyzbar-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pyzbar-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 66b8a96a1487d4c42b77795e9a56ff5d222fa8e512b603019a344f12c75210d4
MD5 f235ecf0d0ec66d70488322f8b487bc2
BLAKE2b-256 d1e45446112fbd7e787ec55d9e4972f57c2bab85acbb9df89912be6fae73f69a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page