医療ガイドライン等のあらゆる文書構造に対応したOCRパイプライン
## 特徴
### 対応する文書構造
– ✅ 通常の表(フラット構造)
– ✅ 階層構造を持つ表(親カテゴリと子項目)
– ✅ プレーンテキスト(段落、箇条書き)
– ✅ フローチャート
– ✅ 混合コンテンツ(表+テキストなど)
### 2つのパイプライン
#### 1. 標準パイプライン(推奨)
`test_openrouter_coordinate_pipeline.py` – すべての構造に対応
– Stage -1: コンテンツタイプ判定
– Stage 0: タイプ別構造化抽出
– Stage 1: F1スコア分析
– Stage 2: Few-shot改善
#### 2. 階層構造特化パイプライン
`hierarchical_ocr_pipeline.py` – 階層表に特化
– 親カテゴリと子要素の混同を防止
– セル結合の正確な展開
### バッチ処理
`batch_hierarchical_ocr.py` – ディレクトリ内の画像を一括処理
## インストール
pip install -r requirements.txt## 環境変数の設定
export OPENROUTER_API_KEY=”your-api-key-here”OpenRouter APIキーは https://openrouter.ai/ で取得してください。
## 使用方法
### 単一画像の処理
#### 標準パイプライン(すべての構造に対応)
python test_openrouter_coordinate_pipeline.py <image_path>#### 階層構造特化パイプライン
python hierarchical_ocr_pipeline.py <image_path>### バッチ処理(ディレクトリ内の全画像を処理)
#### 基本実行(標準パイプライン)
python batch_hierarchical_ocr.py <image_directory>#### 階層構造特化パイプラインを使用
python batch_hierarchical_ocr.py <image_directory> –pipeline hierarchical#### モデル指定
python batch_hierarchical_ocr.py <image_directory> –model qwen/qwen-2.5-vl-72b-instruct#### Stage 1で停止(JSONL生成のみ、標準パイプラインのみ)
python batch_hierarchical_ocr.py <image_directory> –stop-at-jsonl#### JSONLから再開(Stage 2のみ、標準パイプラインのみ)
python batch_hierarchical_ocr.py <image_directory> –resume-from-jsonl## 出力ファイル
処理結果は入力画像と同じディレクトリの `ocr_output/` フォルダに保存されます。
### 標準パイプライン
– `*_stage0_initial.md` – 初回抽出結果(Markdown)
– `*_stage1_analysis.jsonl` – F1スコア分析結果
– `*_stage1_improved.md` – 改善後のMarkdown
– `*_stage1_structured.json` – 構造化JSON
### 階層構造特化パイプライン
– `*_stage0_hierarchical.md` – 初回抽出結果
– `*_stage1_hierarchical_analysis.jsonl` – 分析結果
– `*_stage1_hierarchical_improved.md` – 改善後のMarkdown
## 推奨モデル
– **Qwen 2.5 VL 72B**: `qwen/qwen-2.5-vl-72b-instruct` – バランスが良い
– **Qwen 3 VL 235B**: `qwen/qwen3-vl-235b-a22b-instruct` – 高精度(デフォルト)
## ライセンス
MIT License
## 開発者
takashiyamamoto260110
コメントを残す