Error decoding Data Matrix that is base256 encoded with pylibdmtx

623 views Asked by At

I'm trying to successfully decode Data Matrix barcodes that are base256 encoded using pylibdmtx. When the barcode contains a 0x00 byte the library seems to treat it as a string terminator (null) and ignores the rest of the data in the barcode.

Here is a snippet of code that will create a barcode and decode it:

from pylibdmtx.pylibdmtx import encode, decode
from PIL import Image

message = b'\x16\x05abc\x64\x00\x65\x66g'
print('message:',message)
barcode = encode(message)
img = Image.frombytes('RGB', (barcode.width, barcode.height), barcode.pixels)
# uncomment if you want to save the barcode to a file
#img.save('barcode.png')
decoded = decode(img)
print('decoded:',decoded)
print(' length:',len(decoded[0].data))

Here is the result:

message: b'\x16\x05abcd\x00efg'
decoded: [Decoded(data=b'\x16\x05abcd', rect=Rect(left=9, top=10, width=80, height=79))]
 length: 6

The created barcode reads properly with other online tools and dmtxread invoked from a command line.

Is there a limitation with the python wrappers for libdmtx or something I am doing wrong?

Other Info:

This is the simplest example I could come up with to illustrate the problem. The barcodes are much larger and already in production systems.

I did try the python wrappers for the ZXing library and it did not even recognize many of the barcodes. I am open to using other libraries.

Thank you.

0

There are 0 answers