|
|
@@ -1,4 +1,4 @@
|
|
|
-正在收集工作区信息正在筛选到最相关的信息根据代码分析,我来详细说明文字PDF的判断和处理流程:
|
|
|
+根据代码分析,我来详细说明文字PDF的判断和处理流程:
|
|
|
|
|
|
## 文字PDF判断和处理详细说明
|
|
|
|
|
|
@@ -49,13 +49,10 @@ graph TB
|
|
|
ProcessTable --> CropTable[裁剪表格区域图像]
|
|
|
CropTable --> TableDetect[表格结构检测<br/>RapidTable/StructEqTable]
|
|
|
TableDetect --> TableCells[识别单元格位置]
|
|
|
- TableCells --> CellTextExtract{单元格文本提取}
|
|
|
+ TableCells --> TableOCR[OCR识别<br/>PaddleOCR]
|
|
|
|
|
|
- CellTextExtract -->|文字PDF模式| ExtractCellPDFText[提取PDF文本<br/>根据单元格bbox]
|
|
|
- CellTextExtract -->|需要OCR| TableOCR[OCR识别<br/>PaddleOCR]
|
|
|
-
|
|
|
- ExtractCellPDFText --> TableHTML[生成HTML表格<br/>type: table<br/>content: HTML]
|
|
|
- TableOCR --> TableHTML
|
|
|
+ TableOCR --> TableOCRResult[获取单元格文本]
|
|
|
+ TableOCRResult --> TableHTML[生成HTML表格<br/>type: table<br/>content: HTML]
|
|
|
|
|
|
%% 公式处理分支
|
|
|
ProcessFormula --> FormulaClassify{公式类型检测}
|
|
|
@@ -130,26 +127,19 @@ for bbox in text_bboxes:
|
|
|
text = extract_text_from_bbox(pdf_page, bbox)
|
|
|
```
|
|
|
|
|
|
-### **步骤4: 表格处理(文字PDF)**
|
|
|
+### **步骤4: 表格处理**
|
|
|
```python
|
|
|
# 1. 裁剪表格区域图像
|
|
|
table_image = crop_image(page_image, table_bbox)
|
|
|
|
|
|
-# 2. 表格结构检测
|
|
|
-table_structure = rapidtable_model.predict(table_image)
|
|
|
-# 返回: cells的bbox和行列信息
|
|
|
-
|
|
|
-# 3. 提取单元格文本
|
|
|
-for cell_bbox in table_structure.cells:
|
|
|
- # 文字PDF: 提取PDF文本
|
|
|
- cell_text = extract_text_from_bbox(pdf_page, cell_bbox)
|
|
|
-
|
|
|
- # 如果提取失败,使用OCR
|
|
|
- if not cell_text:
|
|
|
- cell_text = ocr_model.recognize(cell_image)
|
|
|
+# 2. 表格结构检测与内容识别
|
|
|
+# 使用端到端的表格识别模型,或组合使用表格结构识别 + OCR
|
|
|
+# 即使是文字PDF,表格部分目前也主要依赖视觉OCR方案,以保证复杂表格结构的准确恢复
|
|
|
+table_result = table_model.predict(table_image)
|
|
|
+# 返回: HTML格式的表格内容
|
|
|
|
|
|
# 4. 生成HTML
|
|
|
-table_html = generate_html_table(table_structure, cell_texts)
|
|
|
+table_html = table_result['html']
|
|
|
```
|
|
|
|
|
|
### **步骤5: 公式处理**
|
|
|
@@ -189,7 +179,7 @@ middle_json = {
|
|
|
| 特性 | 文字PDF (txt模式) | 图片PDF (ocr模式) |
|
|
|
|------|------------------|------------------|
|
|
|
| **文本提取** | 直接读取PDF文本层 | OCR识别 |
|
|
|
-| **表格单元格** | 优先提取PDF文本,失败才OCR | 全部OCR |
|
|
|
+| **表格单元格** | OCR识别(暂未利用PDF文本层) | OCR识别 |
|
|
|
| **公式识别** | UniMERNet(图像→LaTeX) | 同左 |
|
|
|
| **处理速度** | 快(跳过大部分OCR) | 慢(全页OCR) |
|
|
|
| **准确性** | 文本100%准确 | 依赖OCR质量 |
|