1

我有附加的图像。我尝试使用下面的代码,它为大多数图像输出正确的值。但是,解码需要很长时间。

import cv2
from pylibdmtx.pylibdmtx import decode
import ctypes  
from PIL import Image
decode(Image.open("1591106831_festo.jpg"))

我相信如果我只能选择包含数据矩阵的图像的特定部分并将其输入到 pylibdmtx 库中,它可能会更准确和更快。

但目前我无法弄清楚如何选择带有数据矩阵的图像部分。你能帮帮我吗?谢谢。

附加 DataMatrix 的预期输出为 (91)4608

4

1 回答 1

0

简单地使用cv2pylibdmtx如下

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

这可能比您目前手头的更快,因为我们1)提供decode了不可猜测的参数,并且2)提供了,这image[:, :, :1]意味着一个只处理第一个BGR层,蓝色层,显然足以用于条形码.


为了比较,decode(Image.open("1591106831_festo.jpg"))返回

[Decoded(data=b'(91)4608', rect=Rect(left=650, top=522, width=-82, height=86))]

即完全相同的推论。


你可以做的是限制你想获得的条形码数量,使用max_count参数,

>>> decode(Image.open("1591106831_festo.jpg"), max_count=1)
[Decoded(data=b'(91)4608', rect=Rect(left=522, top=629, width=86, height=82))]
于 2020-06-10T09:41:42.897 回答