From f64bf25f67d37ff314f977e8696c920bf7bd6754 Mon Sep 17 00:00:00 2001 From: liuyuanchuang Date: Mon, 9 Feb 2026 22:23:52 +0800 Subject: [PATCH] fix: image variable not defined --- app/services/ocr_service.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/services/ocr_service.py b/app/services/ocr_service.py index f1eb126..2f65b91 100644 --- a/app/services/ocr_service.py +++ b/app/services/ocr_service.py @@ -683,6 +683,14 @@ class MineruOCRService(OCRServiceBase): Dict with 'markdown', 'latex', 'mathml' keys. """ try: + # Decode image_bytes to numpy array for potential formula recognition + image_bytes.seek(0) + image_data = np.frombuffer(image_bytes.read(), dtype=np.uint8) + original_image = cv2.imdecode(image_data, cv2.IMREAD_COLOR) + + # Reset image_bytes for API request + image_bytes.seek(0) + # Prepare multipart form data files = {"files": ("image.png", image_bytes, "image/png")} @@ -715,7 +723,7 @@ class MineruOCRService(OCRServiceBase): markdown_content = result["results"]["image"].get("md_content", "") if "![](images/" in markdown_content: - markdown_content = self._extract_and_recognize_formulas(markdown_content, image) + markdown_content = self._extract_and_recognize_formulas(markdown_content, original_image) # Apply postprocessing to fix OCR errors markdown_content = _postprocess_markdown(markdown_content)