From d0465ba9094195f6c3e8444b6135a9998158e221 Mon Sep 17 00:00:00 2001 From: Stephen Hu <812791840@qq.com> Date: Mon, 9 Mar 2026 14:16:57 +0800 Subject: [PATCH] refactor: improve paddle ocr logic (#13467) ### What problem does this PR solve? improve paddle ocr logic ### Type of change - [x] Refactoring --- deepdoc/parser/paddleocr_parser.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/deepdoc/parser/paddleocr_parser.py b/deepdoc/parser/paddleocr_parser.py index 28546e1c0f..cb27a72549 100644 --- a/deepdoc/parser/paddleocr_parser.py +++ b/deepdoc/parser/paddleocr_parser.py @@ -63,7 +63,6 @@ def _remove_images_from_markdown(markdown: str) -> str: class PaddleOCRVLConfig: """Configuration for PaddleOCR-VL algorithm.""" - use_doc_orientation_classify: Optional[bool] = False use_doc_orientation_classify: Optional[bool] = False use_doc_unwarping: Optional[bool] = False use_layout_detection: Optional[bool] = None @@ -533,21 +532,25 @@ class PaddleOCRParser(RAGFlowPdfParser): return None, None return - height = 0 + total_height = 0 + max_width = 0 + img_sizes = [] for img in imgs: - height += img.size[1] + GAP - height = int(height) - width = int(np.max([i.size[0] for i in imgs])) - pic = Image.new("RGB", (width, height), (245, 245, 245)) - height = 0 - for ii, img in enumerate(imgs): - if ii == 0 or ii + 1 == len(imgs): + w, h = img.size + img_sizes.append((w, h)) + max_width = max(max_width, w) + total_height += h + GAP + + pic = Image.new("RGB", (max_width, int(total_height)), (245, 245, 245)) + current_height = 0 + imgs_count = len(imgs) + for ii, (img, (w, h)) in enumerate(zip(imgs, img_sizes)): + if ii == 0 or ii + 1 == imgs_count: img = img.convert("RGBA") - overlay = Image.new("RGBA", img.size, (0, 0, 0, 0)) - overlay.putalpha(128) + overlay = Image.new("RGBA", img.size, (0, 0, 0, 128)) img = Image.alpha_composite(img, overlay).convert("RGB") - pic.paste(img, (0, int(height))) - height += img.size[1] + GAP + pic.paste(img, (0, int(current_height))) + current_height += h + GAP if need_position: return pic, positions