Skip to main content

A ctypes-based wrapper around the libdmtx datamatrix barcode reader.

Project description

Python Versions PyPI version Travis status Coverage Status

A ctypes-based Python wrapper around the libdmtx datamatrix barcode reader.

The pydmtx wrapper is stuck in Python 2.x-land. This ctypes-based wrapper brings libdmtx to Python 2.7 and to Python 3.4 or greater.

Installation

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

On Mac OS X:

brew install libdmtx

On Linux:

sudo apt-get install libdmtx0a

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

pip install pylibdmtx
pip install pylibdmtx[scripts]

Example usage

The decode function accepts instances of PIL.Image.

>>> from pylibdmtx.pylibdmtx import decode
>>> from PIL import Image
>>> decode(Image.open('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

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

>>> import cv2
>>> decode(cv2.imread('pylibdmtx/tests/datamatrix.png'))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

You can also provide a tuple (pixels, width, height)

>>> image = cv2.imread('pylibdmtx/tests/datamatrix.png')
>>> height, width = image.shape[:2]
>>> decode((image.tobytes(), width, height))
[Decoded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
 Decoded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]

Limitations

Feel free to submit a PR to address any of these.

  • decoding only - no encoding

  • I took the bone-headed approach of copying the logic in pydmtx’s decode function (in pydmtxmodule.c); there might be more of libdmtx’s functionality that could be used to read barcodes

  • I exposed the bare minimum of functions, defines, enums and typedefs neede to reimplement pydmtx’s decode function

License

pylibdmtx is distributed under the MIT license (see LICENCE.txt). The libdmtx shared library is distributed under the Simplified BSD license (see libdmtx-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

pylibdmtx-0.1.6-py2.py3-none-win_amd64.whl (94.2 kB view details)

Uploaded Python 2Python 3Windows x86-64

pylibdmtx-0.1.6-py2.py3-none-win32.whl (52.8 kB view details)

Uploaded Python 2Python 3Windows x86

pylibdmtx-0.1.6-py2.py3-none-any.whl (18.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pylibdmtx-0.1.6-py2.py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for pylibdmtx-0.1.6-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 3e81cced1aeb16af299aa04ee535b4c83f1c68b143d9b9756871cf0d8153ee7a
MD5 b62de8c3283949f345d0ca1075e4df5f
BLAKE2b-256 864ec031e8150ae69532427fd4e9c11f079c23b9f97bdcbac42b3b88d87f1672

See more details on using hashes here.

File details

Details for the file pylibdmtx-0.1.6-py2.py3-none-win32.whl.

File metadata

File hashes

Hashes for pylibdmtx-0.1.6-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 7576b1307cece1c3e5d94025d08c23b6a5c5e445915a6c04284c91b127e4a263
MD5 c26e7cb500288867fc098fffe5bb41ec
BLAKE2b-256 83f40a500790da0522a48d3dbecae108ffb0577c8db54ae5b2df796c59a0bf45

See more details on using hashes here.

File details

Details for the file pylibdmtx-0.1.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pylibdmtx-0.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2127078f1681741686f561caffc12feeece3250e58e2d7dc810f1908fb51c326
MD5 6c35da6c9e38c477433d2fbd3b95a050
BLAKE2b-256 688973b0fe0ef41496c4125a66c17c307cdf99cd4bb6e300773da894183f6e58

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