Metadata-Version: 2.0
Name: pylibdmtx
Version: 0.1.4
Summary: A ctypes-based wrapper around the libdmtx datamatrix barcode reader.
Home-page: https://github.com/NaturalHistoryMuseum/pylibdmtx/
Author: Lawrence Hudson
Author-email: l.hudson@nhm.ac.uk
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Utilities
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Requires-Dist: enum34 (>=1.1.6); python_version=="2.7"
Requires-Dist: pathlib (>=1.0.1); python_version=="2.7"
Provides-Extra: scripts
Requires-Dist: Pillow (>=3.2.0); extra == 'scripts'

pylibdmtx
=========

|Python Versions| |PyPI version| |Travis status| |Coverage Status|

A ``ctypes``-based Python wrapper around the
`libdmtx <http://libdmtx.sourceforge.net/>`__ datamatrix barcode reader.

The
`pydmtx <https://sourceforge.net/p/libdmtx/dmtx-wrappers/ci/master/tree/python/>`__
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`` ``DLL``\ s 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 <http://opencv.org/>`__.

::

    >>> 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``).

.. |Python Versions| image:: https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5-blue.svg
   :target: https://github.com/NaturalHistoryMuseum/pylibdmtx
.. |PyPI version| image:: https://badge.fury.io/py/pylibdmtx.svg
   :target: https://pypi.python.org/pypi/pylibdmtx/
.. |Travis status| image:: https://travis-ci.org/NaturalHistoryMuseum/pylibdmtx.svg?branch=master
   :target: https://travis-ci.org/NaturalHistoryMuseum/pylibdmtx
.. |Coverage Status| image:: https://coveralls.io/repos/github/NaturalHistoryMuseum/pylibdmtx/badge.svg?branch=master
   :target: https://coveralls.io/github/NaturalHistoryMuseum/pylibdmtx?branch=master


