-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
QrCodeReader decodes only when flipping image #23155
Copy link
Copy link
Closed
Description
System Information
OpenCV python version: 4.7.0.68
Operating System / Platform: Windows 10
Python version: 3.10.9
Detailed description
The decoding of the QRCode detector behaves strangely when the image is flipped. In the example image below there are two QR Codes which are correctly detected by the program but partly not decoded. When the image is not flipped only the right is decoded, when flipped only the left. Should the decoder be able to detect the QR Code when the image is flipped or is this not expected behaviour? When not this would be good to add to the documentation
Steps to reproduce
Working example:
import numpy as np
import cv2
class QrCodeDetector:
def __init__(self) -> None:
self.detector = cv2.QRCodeDetector()
self.detector.setUseAlignmentMarkers(True)
def __call__(self, img: np.ndarray) -> tuple[bool, list[str], np.ndarray]:
found_code, code_strings, corners, _ = self.detector.detectAndDecodeMulti(img)
return (found_code, code_strings, corners)
def draw_rectangle(img: np.ndarray, corner_points: np.ndarray):
corner_points = corner_points.astype(np.int32)[np.newaxis]
return cv2.polylines(img, corner_points, True, (0, 255, 0), 3)
def draw_text(img: np.ndarray, top_left_corner: np.ndarray, text: str):
return cv2.putText(img, text, top_left_corner.astype(int), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
if __name__ == "__main__":
FILENAME = "example.png"
WND = "QR"
detector = QrCodeDetector()
img = cv2.imread(FILENAME)
img = cv2.resize(img, None, fx=0.3, fy=0.3)
#img = cv2.flip(img, 1)
valid, codes, corners = detector(img)
if valid:
for code, corner in zip(codes, corners):
img = draw_rectangle(img, corner)
img = draw_text(img, corner[0], code)
print(codes)
cv2.imshow(WND, img)
cv2.waitKey(0)
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)
Reactions are currently unavailable
