老实说,我正在尝试使用 Python 或任何其他语言来解码 QR 码。我也熟悉 Javascript 或 PHP,但 Python 似乎是最适合这项任务的。
这是我为一个小挑战而编写的更大代码的一部分。我需要从二维码中提取密码。我尝试在手机上使用二维码阅读器,并且可以获取密码,这样我就可以确认二维码本身没有问题。
要检索的字符串是“The key is/qrcod_OMevpf”。
到目前为止,我已经尝试使用两个不同的 python 库。打开CV和Pyzbar,代码如下:
OpenCV
image = cv2.imread(imgAbsolutePath)
qrCodeDetector = cv2.QRCodeDetector()
decodedText, points, _ = qrCodeDetector.detectAndDecode(image)
if points is not None:
# QR Code detected handling code
print("QR code detected")
print(decodedText)
else:
print("QR code not detected")
打印“检测到二维码”,然后打印一个空字符串。
Pyzbar
qr = decode(Image.open('result.png'), symbols=[ZBarSymbol.QRCODE])
print(qr)
打印“[]”
你知道为什么这些不起作用或者你能推荐任何其他有效的库吗? 谢谢
最佳答案
我终于使用 zxing 让它工作了:
from zxing import BarCodeReader
def decode_qr_code(image_path):
reader = BarCodeReader()
barcode = reader.decode(image_path)
return barcode.parsed
qr_code = decode_qr_code("result.png")
print(qr_code)
关于python - 使用 OpenCV 或 Pyzbar 读取 QR 码时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75425729/