OcM*_*RUS 1 python opencv qr-code
我正在尝试解码 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")
Run Code Online (Sandbox Code Playgroud)
它显示空数据,但肯定会看到 QR 代码,因为点数据是: QRCode 数据:
[[[132. 524. ]
[557.0844 513.29724]
[550. 908. ]
[155.88225 920.6455 ]]]
Run Code Online (Sandbox Code Playgroud)
在该示例中,binary_qrcode 为 None。有没有什么特殊的选项可以让cv2识别数据?也许有 QR 解码器的替代品?非常感谢您的建议。
考虑使用Pyzbar,它比使用 cv2 更强大、更快。
您可以按照此处的说明进行安装
安装:
pip install pyzbar
Run Code Online (Sandbox Code Playgroud)
代码:
from pyzbar.pyzbar import decode
image = cv2.imread(filename, 0)
barcodes = decode(image)
print(barcodes)
Run Code Online (Sandbox Code Playgroud)
它打印:
[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')]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3562 次 |
| 最近记录: |