我正在嘗試解碼 QR。有時可以很好地讀取圖片,但即使檢測到二維碼(點),我也經常得到空資料。這是應用程式:
import cv2
# Name of the QR Code Image file
filename = "D:/......./QR_1229444659.jpg"
image = cv2.imread(filename)
detector = cv2.QRCodeDetector()
data, vertices_array, binary_qrcode = detector.detectAndDecode(image)
if vertices_array is not None:
print(f"QRCode data: {data}")
else:
print("There was some error")
這是我要閱讀的 QR:

它顯示空資料,但肯定會看到 QR 碼,因為點資料是: QRCode 資料:
[[[132. 524. ]
[557.0844 513.29724]
[550. 908. ]
[155.88225 920.6455 ]]]
在該示例中, binary_qrcode 為無。是否有任何特殊選項可以讓 cv2 識別資料?QR解碼器可能有替代品嗎?將不勝感激您的建議。
uj5u.com熱心網友回復:
考慮使用比使用cv2更健壯和更快的 Pyzbar。
您可以按照此處的說明進行安裝
安裝:
pip install pyzbar
代碼:
from pyzbar.pyzbar import decode
image = cv2.imread(filename, 0)
barcodes = decode(image)
print(barcodes)
它列印:
[Decoded(data=b'https://energo.onelink.me/gTTu/ENGH081912680001?af_qr=true', type='QRCODE', rect=Rect(left=134, top=515, width=420, height=402), polygon=[Point(x=134, y=525), Point(x=158, y=917), Point(x=547, y=905), Point(x=554, y=515)], quality=1, orientation='UP')]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/488145.html
