-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Unable to decode QR Codes with particular payloads #23810
Description
System Information
OpenCV python version: 4.7.0.72
Operating System: Ubuntu 22.04
Python version: 3.10.6
.venv dump (pip freeze) - also contains other QR detection libraries which were tested:
joblib==1.2.0
numpy==1.24.3
opencv-python==4.7.0.72
py4j==0.10.9.7
PyBoof==0.41
pyzbar==0.1.9
pyzxing==1.0.2
segno==1.5.2
six==1.16.0
transforms3d==0.4.1
Detailed description
I was testing the performance of various QR code detection libraries using "perfect" version 1-H QR codes generated by segno, and I noticed that some of these codes could not be detected. In particular, the following values failed to be detected when testing exhaustively in the range
9133, 24901, 27002, 28211, 30270, 33094, 36997, 37379, 51851, 62533, 63856, 70558, 71054, 74397, 76142, 79599, 91536
This issue was not exclusive to OpenCV, and other tested libraries such as BoofCV also had issues with some payloads (although for different values), which are confirmed as a bug due to false positives in the finder pattern (which may or may not be the same issue in this case) - see lessthanoptimal/PyBoof#23. Please note that there is also an identified bug in segno in which the padding is malformed for 4-digit payloads - see heuer/segno#123, although this does not seem to affect OpenCV as I'm assuming you ignore the padding bits (which seems to be a strategy employed by many detector libraries).
Steps to reproduce
import cv2
import segno
TEST_FILE = 'qr_test.png'
qr_opencv = cv2.QRCodeDetector()
bad_detections = []
for i in range(0, 100000):
qrcode = segno.make(i, version=1)
assert qrcode.error == 'H'
qrcode.save(TEST_FILE, scale = 5)
img = cv2.imread(TEST_FILE)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (88, 88))
detected, points, straight_qrcode = qr_opencv.detectAndDecode(img)
if not detected:
print(f"Unable to detect {i}")
bad_detections.append(i)
else:
assert str(detected) == str(i), f"Mismatch between detected value {detected} and input {x}"
print(f"Unable to detect the following data payloads:\n{bad_detections}")Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)