NaturalHistoryMuseum/pylibdmtx

Name: pylibdmtx

Owner: Natural History Museum

Description: Read Data Matrix barcodes from Python 2 and 3.

Created: 2016-11-01 08:32:59.0

Updated: 2018-05-17 01:29:41.0

Pushed: 2018-05-10 19:11:35.0

Homepage:

Size: 87

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

pylibdmtx

Python Versions PyPI version Travis status Coverage Status

Read Data Matrix barcodes from Python 2 and 3 using the libdmtx library.

The older pydmtx package is stuck in Python 2.x-land.

Installation

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

Mac OS X:

 install libdmtx

Linux:

 apt-get install libdmtx0a

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

install pylibdmtx
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'))
oded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
oded(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'))
oded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
oded(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))
oded(data='Stegosaurus', rect=Rect(left=5, top=6, width=96, height=95)),
oded(data='Plesiosaurus', rect=Rect(left=298, top=6, width=95, height=95))]
Windows error message

If you see an ugly ImportError when importing pylibdmtx on Windows you will most likely need the Visual C++ Redistributable Packages for Visual Studio 2013. Install vcredist_x64.exe if using 64-bit Python, vcredist_x86.exe if using 32-bit Python.

Limitations

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

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.