From 931ab92c926875a5d7a0e51cd2f81420ad963e68 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Sun, 8 Mar 2026 22:31:36 +0100 Subject: [PATCH] feat: Orientierungserkennung in OCR-Pipeline-Deskew integrieren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit detect_and_fix_orientation() wird jetzt vor dem Deskew-Schritt in der OCR-Pipeline ausgefuehrt, sodass 90/180/270°-gedrehte Scans automatisch korrigiert werden. Frontend zeigt Orientierungskorrektur als Info-Banner. Co-Authored-By: Claude Opus 4.6 --- admin-lehrer/app/(admin)/ai/ocr-pipeline/types.ts | 1 + .../components/ocr-pipeline/DeskewControls.tsx | 5 +++++ klausur-service/backend/ocr_pipeline_api.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/admin-lehrer/app/(admin)/ai/ocr-pipeline/types.ts b/admin-lehrer/app/(admin)/ai/ocr-pipeline/types.ts index 78ce81e..d888cf1 100644 --- a/admin-lehrer/app/(admin)/ai/ocr-pipeline/types.ts +++ b/admin-lehrer/app/(admin)/ai/ocr-pipeline/types.ts @@ -85,6 +85,7 @@ export interface DeskewResult { angle_applied: number method_used: 'hough' | 'word_alignment' | 'manual' | 'iterative' | 'two_pass' | 'three_pass' | 'manual_combined' confidence: number + orientation_degrees?: number duration_seconds: number deskewed_image_url: string binarized_image_url: string diff --git a/admin-lehrer/components/ocr-pipeline/DeskewControls.tsx b/admin-lehrer/components/ocr-pipeline/DeskewControls.tsx index c696ac5..c0f493c 100644 --- a/admin-lehrer/components/ocr-pipeline/DeskewControls.tsx +++ b/admin-lehrer/components/ocr-pipeline/DeskewControls.tsx @@ -59,6 +59,11 @@ export function DeskewControls({ {/* Results */} {deskewResult && (
+ {deskewResult.orientation_degrees ? ( +
+ Seite wurde um {deskewResult.orientation_degrees}° gedreht (Orientierungskorrektur) +
+ ) : null}
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),