+ Seite wurde um {deskewResult.orientation_degrees}° gedreht (Orientierungskorrektur)
+
Winkel:{' '}
diff --git a/klausur-service/backend/ocr_pipeline_api.py b/klausur-service/backend/ocr_pipeline_api.py
index d3a3295..cc633f2 100644
--- a/klausur-service/backend/ocr_pipeline_api.py
+++ b/klausur-service/backend/ocr_pipeline_api.py
@@ -54,6 +54,7 @@ from cv_vocab_pipeline import (
deskew_image_by_word_alignment,
deskew_image_iterative,
deskew_two_pass,
+ detect_and_fix_orientation,
detect_column_geometry,
detect_document_type,
detect_row_geometry,
@@ -475,6 +476,16 @@ async def auto_deskew(session_id: str):
t0 = time.time()
+ # Orientation detection (fix 90/180/270° rotations from scanners)
+ img_bgr, orientation_deg = detect_and_fix_orientation(img_bgr)
+ if orientation_deg:
+ # Update original in cache + DB so all subsequent steps use corrected image
+ cached["original_bgr"] = img_bgr
+ success_ori, ori_buf = cv2.imencode(".png", img_bgr)
+ if success_ori:
+ await update_session_db(session_id, original_png=ori_buf.tobytes())
+ logger.info(f"OCR Pipeline: orientation corrected {orientation_deg}° for session {session_id}")
+
# Two-pass deskew: iterative (±5°) + word-alignment residual check
deskewed_bgr, angle_applied, two_pass_debug = deskew_two_pass(img_bgr.copy())
@@ -523,6 +534,7 @@ async def auto_deskew(session_id: str):
"angle_residual": round(angle_residual, 3),
"angle_textline": round(angle_textline, 3),
"angle_applied": round(angle_applied, 3),
+ "orientation_degrees": orientation_deg,
"method_used": method_used,
"confidence": round(confidence, 2),
"duration_seconds": round(duration, 2),
@@ -551,6 +563,7 @@ async def auto_deskew(session_id: str):
f"-> {method_used} total={angle_applied:.2f}")
await _append_pipeline_log(session_id, "deskew", {
+ "orientation": orientation_deg,
"angle_applied": round(angle_applied, 3),
"angle_iterative": round(angle_iterative, 3),
"angle_residual": round(angle_residual, 3),