Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

refactor: improve paddle ocr logic (#13467)

Stephen Hud0465ba90941
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