Libdmtx
From ActiveArchives
Data Matrix is a format, like QR codes, for encoding data as a two dimensional graphical barcode. libdmtx is the free C library with support for creating and decoding. Bindings for other languages, including Python, exist.
Contents |
Using libdmtx from the commandline
Installation
sudo apt-get install libdmtx-utils
Results in:
p libdmtx-dev - Data Matrix barcodes (development files and static libraries) i libdmtx-utils - Utilities for reading and writing Data Matrix 2D barcodes i A libdmtx0a - Data Matrix barcodes (runtime library)
Encoding a message
Created a message in a text file (osv.txt), and then:
dmtxwrite osv.txt -o osv.png
Decoding a message
Decoding directly from the encoded image:
dmtxread osv.png
This time, the image is opened in the gimp, scaled it up, and photographed with a camera phone, then:
dmtxread IMG_20110906_150252.jpg -N1
The same message is decoded!
Decoding messages from a number of images
Display all messages from files ending with "jpg" in the current directory:
dmtxread -N1 -n -m1000 *.jpg
Parameters explained:
- -N1 : stop after 1 code (per image)
- -n : print a new line after each message
- -m1000 : limits search to 1000ms per image (give up if no message is found)
Using libdmtx from Python
Installing the Python bindings
sudo apt-get install libdmtx-dev cd /usr/share/doc/libdmtx-dev/examples/python # unzip the source files! sudo gunzip pydmtx.py.gz sudo gunzip pydmtxmodule.c.gz sudo python setup.py install
Decoding messages
From the Python interface code, the accepted keyword arguments (to just the decode function?):
*kwlist[] = { "width", "height", "data", "gap_size", "max_count", "context", "timeout", "shape", "deviation", "threshold", "shrink", "corrections", "min_edge", "max_edge" };
from pydmtx import DataMatrix from PIL import Image import sys dm_read = DataMatrix() for f in sys.argv[1:]: try: img = Image.open(f) result = dm_read.decode(img.size[0], img.size[1], buffer(img.tostring()), timeout=1000, max_count=1) print f, result except IOError: print "Bad image (IOError):", f
