diff --git a/paddleocr-service/main.py b/paddleocr-service/main.py index 04b7e77..c795294 100644 --- a/paddleocr-service/main.py +++ b/paddleocr-service/main.py @@ -88,10 +88,17 @@ async def ocr( img = Image.open(io.BytesIO(img_bytes)).convert("RGB") img_np = np.array(img) - result = _engine.ocr(img_np) + try: + result = _engine.ocr(img_np) + except Exception as e: + logger.error(f"OCR failed: {e}", exc_info=True) + raise HTTPException(status_code=500, detail=f"OCR processing failed: {e}") + + if not result or not result[0]: + return {"words": [], "image_width": img_np.shape[1], "image_height": img_np.shape[0]} words = [] - for line in result[0] or []: + for line in result[0]: box, (text, conf) = line[0], line[1] x_min = min(p[0] for p in box) y_min = min(p[1] for p in box)