From 0d3f001acbfef3181fe20f55b4233780e52dce14 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Wed, 4 Mar 2026 09:05:43 +0100 Subject: [PATCH] fix: always include detections in dewarp response, even when no correction applied The detections array was empty when shear was below threshold, hiding all 4 method results from the frontend Details panel. Co-Authored-By: Claude Opus 4.6 --- klausur-service/backend/cv_vocab_pipeline.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/klausur-service/backend/cv_vocab_pipeline.py b/klausur-service/backend/cv_vocab_pipeline.py index 2a9ae7c..7c2d09d 100644 --- a/klausur-service/backend/cv_vocab_pipeline.py +++ b/klausur-service/backend/cv_vocab_pipeline.py @@ -903,8 +903,16 @@ def dewarp_image(img: np.ndarray, use_ensemble: bool = True) -> Tuple[np.ndarray detections[3]["confidence"] if len(detections) > 3 else 0.0, ) + # Always include individual detections (even when no correction applied) + _all_detections = [ + {"method": d["method"], "shear_degrees": d["shear_degrees"], + "confidence": d["confidence"]} + for d in detections + ] + # Higher thresholds: subtle shear (<0.15°) is irrelevant for OCR if abs(shear_deg) < 0.15 or confidence < 0.5: + no_correction["detections"] = _all_detections return img, no_correction # Apply correction (negate the detected shear to straighten) @@ -914,22 +922,14 @@ def dewarp_image(img: np.ndarray, use_ensemble: bool = True) -> Tuple[np.ndarray if not _dewarp_quality_check(img, corrected): logger.info("dewarp: quality gate REJECTED correction (%.3f°) — " "projection variance did not improve", shear_deg) - no_correction["detections"] = [ - {"method": d["method"], "shear_degrees": d["shear_degrees"], - "confidence": d["confidence"]} - for d in detections - ] + no_correction["detections"] = _all_detections return img, no_correction info = { "method": method, "shear_degrees": shear_deg, "confidence": confidence, - "detections": [ - {"method": d["method"], "shear_degrees": d["shear_degrees"], - "confidence": d["confidence"]} - for d in detections - ], + "detections": _all_detections, } return corrected, info