I am trying to decode QR. Sometimes picture can be read well, but very often I got empty data back even if QR code was detected (points). Here is the app:
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")
Here is the QR what I am trying to read:
it shows empty data back but definately see the QR code as points data are: QRCode data:
[[[132. 524. ]
[557.0844 513.29724]
[550. 908. ]
[155.88225 920.6455 ]]]
In that example binary_qrcode is None. is there any special option to let cv2 recognize the data? Probably there is an alternative to that QR decoder? Would appreciate your recommendations.
Consider using Pyzbar which is more robust and faster than using cv2.
You can install it following the instructions from here
Installation:
pip install pyzbar
Code:
from pyzbar.pyzbar import decode
image = cv2.imread(filename, 0)
barcodes = decode(image)
print(barcodes)
It prints:
[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')]