Files
OCR/openspec/changes/extract-table-cell-boxes/tasks.md
egg 5ddccbf5a2 docs: update tasks.md with Phase 1-3 completion status
Mark completed tasks in extract-table-cell-boxes proposal:
- Phase 1: Config and model caching ✓
- Phase 2: Cell boxes extraction ✓
- Phase 3: PDF generation optimization ✓

Remaining: Phase 4 (testing) and Phase 5 (cleanup)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 12:20:59 +08:00

2.7 KiB

Tasks: Extract Table Cell Boxes

Phase 1: 基礎設施

Task 1.1: 添加配置項

  • config.py 添加 enable_table_cell_boxes_extraction 配置
  • 確認現有的表格模型配置可用

Task 1.2: 模型緩存機制

  • PPStructureEnhanced 中添加模型緩存屬性
  • 實現延遲載入邏輯
  • 添加模型釋放方法(可選)

Phase 2: Cell Boxes 提取

Task 2.1: 修改表格處理邏輯

  • _process_parsing_res_list 中添加 cell boxes 提取
  • 實現圖片裁切邏輯
  • 調用 SLANeXt 模型獲取結果

Task 2.2: 座標轉換

  • 實現相對座標到全域座標的轉換
  • 處理 ScalingInfo 的座標縮放
  • 驗證座標轉換正確性

Task 2.3: 錯誤處理

  • 添加 try-catch 包裝
  • 實現失敗時的降級處理
  • 添加適當的日誌記錄

Phase 3: PDF 生成優化

Task 3.1: 利用 Cell Boxes 渲染表格

  • 修改 draw_table_region 使用 cell_boxes
  • 根據實際 cell 位置計算行高列寬
  • 測試渲染效果

Task 3.2: 備選方案

  • 當 cell_boxes 不可用時,使用現有邏輯
  • 確保向後兼容

Phase 4: 測試與驗證

Task 4.1: 單元測試

  • 測試 cell boxes 提取功能
  • 測試座標轉換
  • 測試錯誤處理

Task 4.2: 整合測試

  • 使用實際 PDF 測試 OCR Track
  • 驗證 PDF 版面還原效果
  • 性能測試

Phase 5: 清理

Task 5.1: 移除舊代碼

  • 評估並移除不再需要的 Paragraph 包裝代碼
  • 清理調試日誌
  • 更新文檔

技術細節

關鍵代碼位置

文件 修改內容
backend/app/core/config.py 添加配置項
backend/app/services/pp_structure_enhanced.py 主要實現
backend/app/services/pdf_generator_service.py 利用 cell_boxes

依賴

from paddlex import create_model

測試數據

  • Task ID: 79a3d256-88f6-41d4-a7e9-3e358c85db40
  • 表格 bbox: [84, 269, 1174, 1508]
  • 預期 cell 數量: 29 (SLANeXt_wired)

實現摘要

已完成 (715805b):

  1. config.py: 添加 enable_table_cell_boxes_extraction 配置項
  2. pp_structure_enhanced.py:
    • 添加 _slanet_wired_model, _slanet_wireless_model, _table_cls_model 緩存屬性
    • 實現 _get_slanet_model()_get_table_classifier() 延遲載入
    • 實現 _extract_cell_boxes_with_slanet() 從裁切圖片提取 cell boxes
    • 實現 release_slanet_models() 釋放 GPU 記憶體
    • 修改表格處理邏輯,當 PPStructureV3 沒有返回 boxes 時調用 SLANeXt
  3. pdf_generator_service.py:
    • 添加 _compute_table_grid_from_cell_boxes() 計算列寬和行高
    • 修改 draw_table_region() 優先使用 cell_boxes 計算列寬