diff --git a/paddleocr-service/main.py b/paddleocr-service/main.py index 1195c5e..179c44b 100644 --- a/paddleocr-service/main.py +++ b/paddleocr-service/main.py @@ -19,8 +19,11 @@ def get_engine(): from paddleocr import PaddleOCR _engine = PaddleOCR( - lang="latin", - use_angle_cls=True, + lang="en", + text_recognition_model_name="latin_PP-OCRv5_mobile_rec", + use_doc_orientation_classify=False, + use_doc_unwarping=False, + use_textline_orientation=False, show_log=False, ) return _engine @@ -44,25 +47,31 @@ async def ocr( img_np = np.array(img) engine = get_engine() - result = engine.ocr(img_np) + result = engine.predict(img_np) words = [] - for line in result[0] or []: - 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) - x_max = max(p[0] for p in box) - y_max = max(p[1] for p in box) - words.append( - { - "text": text, - "left": int(x_min), - "top": int(y_min), - "width": int(x_max - x_min), - "height": int(y_max - y_min), - "conf": round(conf * 100, 1), - } - ) + for item in result: + rec_texts = item.get("rec_texts", []) + rec_scores = item.get("rec_scores", []) + dt_polys = item.get("dt_polys", []) + + for text, score, poly in zip(rec_texts, rec_scores, dt_polys): + if not text or not text.strip(): + continue + xs = [p[0] for p in poly] + ys = [p[1] for p in poly] + x_min, x_max = min(xs), max(xs) + y_min, y_max = min(ys), max(ys) + words.append( + { + "text": text.strip(), + "left": int(x_min), + "top": int(y_min), + "width": int(x_max - x_min), + "height": int(y_max - y_min), + "conf": round(float(score) * 100, 1), + } + ) return { "words": words,