0

我正在尝试成功解码使用 pylibdmtx 编码的 base256 数据矩阵条形码。当条形码包含 0x00 字节时,库似乎将其视为字符串终止符(null)并忽略条形码中的其余数据。

这是一段将创建条形码并对其进行解码的代码片段:

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

结果如下:

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

使用其他在线工具和从命令行调用的 dmtxread 可以正确读取创建的条形码。

libdmtx 的 python 包装器是否有限制或我做错了什么?

其他信息:

这是我能想出的最简单的例子来说明这个问题。条形码要大得多,并且已经在生产系统中。

我确实尝试了 ZXing 库的 python 包装器,它甚至无法识别许多条形码。我愿意使用其他库。

谢谢你。

4

0 回答 0