Skip to main content

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 <https://sourceforge.net/p/libdmtx/dmtx-wrappers/ci/master/tree/python/>`__); 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).

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

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3Windows x86-64

pylibdmtx-0.1.5-py2.py3-none-win32.whl (52.7 kB view details)

Uploaded Python 2Python 3Windows x86

pylibdmtx-0.1.5-py2.py3-none-any.whl (17.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for pylibdmtx-0.1.5-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 9b3f23b01b13463d52b941cd7414d35e6e260c83b194933f492f012a646208d1
MD5 ed45466fda8d485ad6dde31d616ad5af
BLAKE2b-256 f0cb765e5898844147b1a5ba87d94181d39e50c66d62e81c57b35fecb41621d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pylibdmtx-0.1.5-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 cbcc040940df59c96b13d32abbc431cac4b38b8bf4979e3b0a5e50ba2570c60f
MD5 7dc336e7a64cc56caea48a16713a3abf
BLAKE2b-256 6c71c6dc4f0762ee9a1cc746f8c4d9482fed49bdadbe5d5e269e0564a1953bdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pylibdmtx-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4c1f2656369ec09aed9abbca12784fb654d12bbfc382aa81dad4740410396c78
MD5 e11bb545104d4a363d107310b1417fd5
BLAKE2b-256 f141b00d6ee5c55ad1c63f005f5da6dc5aba15188162c195f069324bea0058ae

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.10

3 files

0.1.9

3 files

0.1.8

3 files

0.1.7

3 files

0.1.6

3 files

This release

0.1.5 This release

3 files

0.1.4

3 files

0.1.3

3 files

0.1.2

3 files

0.1.1

3 files

0.1.0

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page