【问题标题】:Getting decoded value from pylibdmtx.pylibdmtx.decode从 pylibdmtx.pylibdmtx.decode 获取解码值
【发布时间】:2021-06-02 03:38:39
【问题描述】:

我正在使用 pylibdmtx.pylibdmtx 读取数据矩阵图像,我能够成功读取图像,但结果我得到了解码格式,例如:[Decoded(data=b'05251255541/001430/HS21CS',矩形=矩形(左=193,顶部=138,宽度=280,高度=277))]。有人可以帮我从这种格式中提取文本吗?

image = cv2.imread(image_name, cv2.IMREAD_UNCHANGED)
print(image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
msg = decode(thresh)
print(msg)```

【问题讨论】:

  • 访问文本可能只是msg.data。 pylibdmtx 文档会告诉你返回的对象有哪些属性。

标签: python opencv qr-code decoding datamatrix


【解决方案1】:

这里是提取解码列表元素的示例代码:

import cv2
from pylibdmtx.pylibdmtx import decode

img = cv2.imread('datamatrix_multiple.png')
decodedList = decode(img)

print(decodedList)
print(len(decodedList))

for i in range(len(decodedList)):
    print(decodedList[i].data)
    print(str(decodedList[i].data, "utf-8")) #removes the b'... formatting
    print(decodedList[i].rect.left)
    print(decodedList[i].rect.top)
    print(decodedList[i].rect.width)
    print(decodedList[i].rect.height)

为带有两个示例数据矩阵代码的图像打印以下内容:

[Decoded(data=b'Hello World', rect=Rect(left=64, top=43, width=285, height=150)), Decoded(data=b'12340000001234', rect=Rect(left=58, top=267, width=70, height=70))]
2
b'Hello World'
Hello World
64
43
285
150
b'12340000001234'
12340000001234
58
267
70
70

【讨论】:

    猜你喜欢
    • 2015-01-12
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2016-08-19
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多