ソースを参照

feat: implement conversion of large text blocks to tables in post-processing, improving layout organization and enhancing document structure recognition

zhch158_admin 5 日 前
コミット
f42b493c9e
1 ファイル変更19 行追加0 行削除
  1. 19 0
      zhch/universal_doc_parser/core/pipeline_manager_v2.py

+ 19 - 0
zhch/universal_doc_parser/core/pipeline_manager_v2.py

@@ -299,6 +299,25 @@ class EnhancedDocPipeline:
             if removed_count > 0:
                 logger.info(f"🔄 Page {page_idx}: removed {removed_count} overlapping boxes")
         
+        # 2.6 将大面积文本块转换为表格(后处理)
+        if layout_results:
+            convert_large_text = self.config.get('layout', {}).get('convert_large_text_to_table', True)
+            if convert_large_text:
+                # 获取图像尺寸 (height, width)
+                img_shape = detection_image.shape
+                if len(img_shape) >= 2:
+                    image_shape = (int(img_shape[0]), int(img_shape[1]))
+                else:
+                    image_shape = (0, 0)
+                
+                layout_results = LayoutUtils.convert_large_text_to_table(
+                    layout_results,
+                    image_shape,
+                    min_area_ratio=self.config.get('layout', {}).get('min_text_area_ratio', 0.25),
+                    min_width_ratio=self.config.get('layout', {}).get('min_text_width_ratio', 0.4),
+                    min_height_ratio=self.config.get('layout', {}).get('min_text_height_ratio', 0.3)
+                )
+        
         page_result['layout_raw'] = layout_results
         
         # 3. 整页 OCR 获取所有 text spans(关键改进)