Ver código fonte

feat: 添加 pdf_type 参数以支持不同的 PDF 处理模式,优化识别逻辑

zhch158_admin 6 dias atrás
pai
commit
ca0374db5f

+ 4 - 1
ocr_tools/universal_doc_parser/models/adapters/mineru_wired_table.py

@@ -181,6 +181,7 @@ class MinerUWiredTableRecognizer:
         self,
         self,
         table_image: np.ndarray,
         table_image: np.ndarray,
         ocr_boxes: List[Dict[str, Any]],
         ocr_boxes: List[Dict[str, Any]],
+        pdf_type: str = 'ocr', # 'ocr' 或 'txt'
         debug_options: Optional[Dict[str, Any]] = None,
         debug_options: Optional[Dict[str, Any]] = None,
     ) -> Dict[str, Any]:
     ) -> Dict[str, Any]:
         """
         """
@@ -387,6 +388,7 @@ class MinerUWiredTableRecognizer:
                 texts = self.text_filler.second_pass_ocr_fill(
                 texts = self.text_filler.second_pass_ocr_fill(
                     table_image, bboxes_merged, texts, scores, 
                     table_image, bboxes_merged, texts, scores, 
                     need_reocr_indices=need_reocr_indices,
                     need_reocr_indices=need_reocr_indices,
+                    pdf_type=pdf_type,
                     force_all=False,  # Force Per-Cell OCR
                     force_all=False,  # Force Per-Cell OCR
                     output_dir=output_dir
                     output_dir=output_dir
                 )
                 )
@@ -454,6 +456,7 @@ class MinerUWiredTableRecognizer:
         self,
         self,
         table_image: np.ndarray,
         table_image: np.ndarray,
         ocr_boxes: List[Dict[str, Any]],
         ocr_boxes: List[Dict[str, Any]],
+        pdf_type: str = 'ocr',
         debug_options: Optional[Dict[str, Any]] = None,
         debug_options: Optional[Dict[str, Any]] = None,
     ) -> Dict[str, Any]:
     ) -> Dict[str, Any]:
         """
         """
@@ -470,7 +473,7 @@ class MinerUWiredTableRecognizer:
                     self.config, 
                     self.config, 
                     override=debug_options or self.debug_options.__dict__
                     override=debug_options or self.debug_options.__dict__
                 )
                 )
-                return self.recognize_v4(table_image, ocr_boxes, debug_options=merged_debug_opts.__dict__)
+                return self.recognize_v4(table_image, ocr_boxes, pdf_type=pdf_type, debug_options=merged_debug_opts.__dict__)
             except Exception:
             except Exception:
                 # 回退
                 # 回退
                 return self.recognize_legacy(table_image, ocr_boxes)
                 return self.recognize_legacy(table_image, ocr_boxes)