I have the image as attached. I tried using the below code and it outputs the correct values for most of the images. But however it takes a long time to decode.
import cv2
from pylibdmtx.pylibdmtx import decode
import ctypes
from PIL import Image
decode(Image.open("1591106831_festo.jpg"))
I believe if I can select only the particular section of the image that contains the data matrix and input it to the pylibdmtx library it might be more accurate and faster.
But currently i'm unable to figure out how to select the section of image with data matrix. Could you please help me out. Thanks.
Expected output for the attached DataMatrix is (91)4608
What about simply using cv2
and pylibdmtx
as follows
import cv2
from pylibdmtx.pylibdmtx import decode
image = cv2.imread("1591106831_festo.jpg")
h, w = image.shape[:2]
decdd = decode((image[:, :, :1].tobytes(), w, h))
print(decdd)
# [Decoded(data=b'(91)4608', rect=Rect(left=650, top=522, width=-82, height=86))]
Which is probably faster that what you currently have in hand since we 1) provide decode
with not-to-be-guessed parameters and 2) do image[:, :, :1]
, which means that one only deals with the first BGR layer, the blue one, clearly sufficient for barcodes.
decode(Image.open("1591106831_festo.jpg"))
returns
[Decoded(data=b'(91)4608', rect=Rect(left=650, top=522, width=-82, height=86))]
i.e. the exact same inference.
max_count
argument,
>>> decode(Image.open("1591106831_festo.jpg"), max_count=1)
[Decoded(data=b'(91)4608', rect=Rect(left=522, top=629, width=86, height=82))]