0

我正在使用 pylibdmtx.pylibdmtx 读取数据矩阵图像,我能够成功读取图像,但结果我得到了解码格式,如:[Decoded(data=b'05251255541/001430/HS21CS', rect=Rect (左=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)```
4

1 回答 1

0

Here is example code to extract the decode list elements:

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)

Which prints out the following for an image with two sample datamatrix codes:

[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
于 2021-11-27T17:17:33.920 回答