1

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

1 Answer 1

0

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.


For the sake of comparison, 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.


Something you can do is limit the number of barcodes you want to get, using the 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))]
Sign up to request clarification or add additional context in comments.

3 Comments

hey,thanks,it partially helps..but are you aware of any method to select just the portion with the datamatrix?
I just checked both the solutions yours and mine, they took around the same time to execute.
including max_count, reduces time drastically mate. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.