From 438a4495c7cac1fdf8763fca57999eb06754edc3 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 17 Mar 2026 16:39:15 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20swap=2090=C2=B0/270=C2=B0=20rotation=20d?= =?UTF-8?q?irection=20in=20orientation=20detection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tesseract OSD 'rotate' returns the clockwise correction needed, but the code was applying counterclockwise for 90° and clockwise for 270° — exactly reversed. This caused pages scanned sideways to be flipped upside down instead of corrected. Co-Authored-By: Claude Opus 4.6 --- klausur-service/backend/cv_preprocessing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/klausur-service/backend/cv_preprocessing.py b/klausur-service/backend/cv_preprocessing.py index 133d47f..71c4f50 100644 --- a/klausur-service/backend/cv_preprocessing.py +++ b/klausur-service/backend/cv_preprocessing.py @@ -113,13 +113,13 @@ def detect_and_fix_orientation(img_bgr: np.ndarray) -> Tuple[np.ndarray, int]: if rotate == 0 or confidence < 1.0: return img_bgr, 0 - # Apply rotation + # Apply rotation — OSD rotate is the clockwise correction needed if rotate == 180: corrected = cv2.rotate(img_bgr, cv2.ROTATE_180) elif rotate == 90: - corrected = cv2.rotate(img_bgr, cv2.ROTATE_90_COUNTERCLOCKWISE) - elif rotate == 270: corrected = cv2.rotate(img_bgr, cv2.ROTATE_90_CLOCKWISE) + elif rotate == 270: + corrected = cv2.rotate(img_bgr, cv2.ROTATE_90_COUNTERCLOCKWISE) else: return img_bgr, 0