Based on the fact that dmtxread correctly handles decoding of data
containing null bytes I have created a temporary workaround.
The result of decoding in Python is used only to identify the rectangle
containing the code.
That rectangle is then saved to the file and os.system is used to decode
it with dmtxread.
It is a "quick & dirty" solution, but at least works...
--
Regards,
Wojtek
#!/usr/bin/python
from pylibdmtx.pylibdmtx import decode
from PIL import Image
import os
# Read the scanned test
img = Image.open("demo.png")
if img.mode != 'RGB':
img = img.convert('RGB')
# The timeout value (and other options) below may need adjustment
# If you know any better way how to reasonable control
# precision of the dmtx decoding, please let me know
dm_read=decode(img)
for i in range(0,len(dm_read)):
fout="demo_out_"+str(i)+".bin"
r=dm_read[i].rect
b=(r.left,r.top,r.left+r.width,r.top+r.height)
ic=img.crop(b)
img.save("code.png")
os.system("dmtxread code.png > "+fout)