diff --git a/klausur-service/backend/ocr_pipeline_api.py b/klausur-service/backend/ocr_pipeline_api.py index 70b3c2e..9f84987 100644 --- a/klausur-service/backend/ocr_pipeline_api.py +++ b/klausur-service/backend/ocr_pipeline_api.py @@ -127,6 +127,12 @@ async def _load_session_to_cache(session_id: str) -> Dict[str, Any]: bgr = cv2.imdecode(arr, cv2.IMREAD_COLOR) cache_entry[bgr_key] = bgr + # Sub-sessions: original image IS the cropped box region. + # Promote original_bgr to cropped_bgr so downstream steps find it. + if session.get("parent_session_id") and cache_entry["original_bgr"] is not None: + if cache_entry["cropped_bgr"] is None and cache_entry["dewarped_bgr"] is None: + cache_entry["cropped_bgr"] = cache_entry["original_bgr"] + _cache[session_id] = cache_entry return cache_entry @@ -465,13 +471,16 @@ async def create_box_sessions(session_id: str): ) # Cache the BGR for immediate processing + # Promote original to cropped so column/row/word detection finds it + box_bgr = crop.copy() _cache[sub_id] = { "id": sub_id, "filename": session.get("filename", "box-crop.png"), "name": sub_name, - "original_bgr": crop.copy(), + "parent_session_id": session_id, + "original_bgr": box_bgr, "oriented_bgr": None, - "cropped_bgr": None, + "cropped_bgr": box_bgr, "deskewed_bgr": None, "dewarped_bgr": None, "orientation_result": None,