Of course in my workaround.py there was a mistake. Instead of:

    img.save("code.png")

there should be:

   ic.save("code.png")

--

Regards,
Wojtek

W dniu 24.11.2022 o 11:14, Wojciech Zabołotny pisze:
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...
#!/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)
    ic.save("code.png")
    os.system("dmtxread code.png > "+fout)

Reply via email to