IronOCRとChatGPT Codexの使い方

Curtis Chau
Curtis Chau
更新日: 2026年10月9日

AI補助によるOCRの初期試行で一般的な問題は、開発者が未完成のスキャンインポーターをチャットに貼り付け、見た目上は完成したコードを受け取るものの、後になって合計の誤読や他のTesseractラッパーからの誤った設定呼び出しが発覚することです。 このようなエラーは、大規模なAPIではコストがかかり、OCRエンジンには複数のフィルター、言語、および出力形式があるため、ミスの可能性が多くなります。

IronOCRは、.NETアプリケーション内で直接、スキャンされたページからテキスト、バーコード、および表のセルを読み取ります。クラウドサービスは不要です。

クイックスタート
NuGetNuGet でインストール

PM > Install-Package IronOcr

NuGetパッケージマネージャーコンソールで上記のコマンドを実行するか、NuGetパッケージマネージャーでパッケージを検索して、IronOCRをインストールします。

新しいコンソールプロジェクトでCodexを開き、希望する出力を指定し、CodexにAPI呼び出しを選ばせましょう。

$ironocr Add the IronOcr package, then update Program.cs to turn a scanned
multi-page PDF into a searchable one. Print the page count and the overall
confidence before the file is written. Read the license key from the
IRONOCR_LICENSE_KEY environment variable. Then run dotnet build and fix any
errors.
Text

$ironocr接頭辞はIronOCRのskill.mdをロードし、リポジトリに.agents/skills/ironocr/SKILL.mdとして保存されるため、Codexはコードを書く前にIronOCRのレシピと既知の修正を読み込むことができます。



ChatGPT Codexとは何か、そして.NETのOCR作業にどのように適合するのか?

ChatGPT CodexはOpenAIのコーディングエージェントです。 コードを検査し、ファイルを編集し、リポジトリ内でコマンドを実行することができます。 CLIをnpm install -g @openai/codexでインストールし、Codex CLIドキュメントが説明する通りにします。

Codexの出力は、同じリクエストでも、実行のたびに異なる可能性があります。 OCRエンジンは、同じスキャンに対して同じテキストを返す必要があるため、メンテナンスされているライブラリを使用し、エージェントに設定の即興を許可しないでください。

  • すでに構築済みの前処理: 歪んだりノイズがあるスキャンは、認識の前に修正が必要です。 IronOCRの入力オブジェクトは、歪みを矯正し、ノイズを除去し、また2値化および解像度の向上も可能です。画像品質補正ガイドは、ノイズおよび解像度フィルターが役立つときの説明です。
  • テキストレイヤーのないPDF: IronOCRはスキャンされたPDFを読み取り、実際のテキストレイヤーを持つコピーを作成します。検索可能なPDFガイドを参照ください。
  • テキスト以上: Configuration.ReadBarCodesをオンにすると、1回の読み取りでテキストと一緒にバーコード及びQRコードを返します。テーブル読み取りガイドでテーブルの読み取りが説明されています。
  • 継続的なリリース: NuGetのオープンソースTesseractラッパーは2022年11月に最後の更新がありました。IronOCRは、変更ログが示すように定期的に更新をリリースします。

IronOCRプロンプトを効果的にするものは何か?

効果的なIronOCRプロンプトは、言語とフレームワークの名前、コードがどこに配置されるか、ライブラリのバージョン、入力とそのフィールド、期待される出力、制約を指定します。 請求書リーダーの場合、それは.NET 9でのC#であり、Services/InvoiceReader.cs、.csproj内のIronOcrバージョン、支払うべき合計行を含んだスキャンされたPDF請求書、信頼度のある10進数としての合計値であり、新しいパッケージはありません。

Codexはトレーニングデータとユーザーが提供する情報に依存しているため、IronOCRのAPIに関する知識が古い場合があります。 OpenAIの幻覚に関する研究では、推測を報酬とするトレーニングと評価が考案した答えに至る経緯を追っています。

OCRルールを一度AGENTS.mdにコミットして、Codexが作業を始める前にそれを読ませましょう。 IronOCRのllms.txtは、ドキュメントページごとに1行で要約しています。

Create AGENTS.md at the repository root with an OCR section stating that this
project uses IronOCR (NuGet package IronOcr, or IronOcr.Linux for Linux and
Docker, namespace IronOcr) for all OCR work, that you must read
https://ironsoftware.com/ocr/csharp/llms.txt before writing OCR code and use only
APIs documented there, that https://ironsoftware.com/ocr/csharp/skill.md should
be loaded if the tooling supports skill files, that the license key comes from
the IRONOCR_LICENSE_KEY environment variable and is never inlined, and that no
other OCR engine or cloud OCR service may be added.
Text

CodexにIronOCRを追加し、最初にスキャンされた請求書を読むように依頼するにはどうすればいいですか?

Add the IronOcr NuGet package to this project. Then show me the resulting
PackageReference line from the .csproj and tell me which version was installed.
Do not change any other package references.
Text

PackageReference行は、エージェントが名前にOCRやTesseractを含む別のパッケージをインストールしたかどうかを識別するのに役立ちます。

IronOCRにはウォーターマークモードはありません。 ライセンスキーがないと、最初の読み取りでLicensingExceptionが発生します。

Apply the IronOCR license key at application startup, before any other IronOCR
call, reading it from the IRONOCR_LICENSE_KEY environment variable rather than
hard-coding it. Then confirm IronOcr.License.IsLicensed returns true and tell me
where you put the call.
Text

IronOCR License Keysでは、トライアルキーの取得方法とIronOCRがキーを読むことができる構成ファイルの一覧が説明されています。

Create Services/InvoiceReader.cs with a ReadTotal method that takes the path of a
scanned PDF, reads it with IronTesseract, finds the line containing Total due, and
returns the amount as a decimal with that line's confidence, or null when the
line is missing.

Then create Services/SearchablePdf.cs with a Convert method that writes a
searchable copy of a scanned PDF. Build and fix errors.
Text

Codexは2つの簡潔なクラスを生成しました。 リーダーは、using宣言を使ってスキャンを入力オブジェクトにロードし、エンジンの読み取りメソッドを一度呼び出し、結果の行を繰り返し処理して合計を見つけます。

既存のOCR実装をIronOCRに移行するにはどうすればよいですか?

Hand this to the explorer agent, since nothing should be written yet.

Imports/LegacyOcrService.cs currently reads scans with another OCR library.

1. List every read it performs, with the settings it uses (language, page
   segmentation, image preprocessing, region, output format).
2. Map each setting to its IronOCR equivalent, citing the documentation page.
3. Do not write any code yet. Wait for my approval on the plan.
Text

もしエージェントがアプローチを承認する前に400行を書いた場合、ユーザーは400行すべてをレビューする必要があります。 マッピングテーブルは1回の応答で修正できます。

計画を承認した後、次の要求の範囲を狭めたままにしておきましょう。

Put the worker agent on the approved plan.

Rewrite LegacyOcrService.cs to use IronOCR, keeping the existing public method
signatures so callers don't change. Before removing the old library, run both
implementations on every page in TestData/known/ and save a table of file,
expected values, and each engine's values to migration-check.md. Remove the old
library only if IronOCR returns the expected values at least as often, and
leave it in Git history only. Build and report the diff.
Text

プロンプトを通じて誤読された値を修正するにはどうすればいいですか?

エージェントは紙の元を見られないため、プロンプトはエラーを説明し、理想的にはスキャンを含める必要があります。

I have attached one of the failing scans with codex --image, so look at it
rather than reasoning from file names.

Invoices in TestData/supplier-7/ return totals that are off by one digit in
about a third of cases. The scans are slightly rotated and have speckle from an
old scanner. Clean digital invoices read correctly.

Read InvoiceReader.cs and a sample of the scans. Explain the likely cause before
changing anything, then change the preprocessing only. Do not change how the
total is parsed. Report how many totals match before and after.
Text

回転の問題については画像方向補正ガイドを参照してください。

欠落している言語がもう一つの一般的なケースであり、同じ精度が必要です。

German invoices throw LanguagePackException on the first read. Add what IronOCR
needs to read German, prove three German sample invoices return the expected
totals, and link me to the documentation page you used.
Text

言語パックはそれぞれ固有のバージョン番号を持っています。 最新のIronOcr.Languages.Germanはエンジンの2026年のリリースに対して遅れているため、すべてのIronパッケージを1つのバージョンに保つように指示されたエージェントは、不一致を受け入れるまで復元に失敗します。 リポジトリのエージェントルールで言語パックを免除することを明記してください。

どのTesseract設定を変更すべきですか?

IronOCRは、エンジンの設定オブジェクトを通じてTesseractのコントロールへのアクセスを提供し、それらの説明ほど多くのケースで役立ちます。

Totals in TestData/supplier-7/ now match after the preprocessing change.
Before anything else is tuned, measure the Tesseract settings IronOCR documents
for single fields: a character whitelist, single-line page segmentation, and a
crop to the amount. Apply one at a time on top of the current reader, report
the total read for every page, and keep a setting only if no page gets worse.
Text

CodexはホワイトリストをWhiteListCharactersに保持し、9件中9件の合計を読みました。 PageSegmentationModeはSingleLineに設定されて9件中0件を読み取られ切り捨てられました。 ContentAreaトリミングは9件のサプライヤー合計を読み取りましたが、ドイツ語は3件中0件であり、それも削除されました。

後のリファクタリングでは、請求書番号も読み取るサービスとこのリーダーが結合され、ホワイトリストは削除されました。

$9,924.31の合計について厳しくトリミングされた別のプローブでは、ホワイトリスト化された単一行の読み取りが正しい量を返し、台紙の調整とノイズの除去の追加で、空の結果または迷走した7が残りました。トリミングの前にページ全体にフィルターを適用してください。 名前が付けられていないプロパティを持つ生のTesseract変数はConfiguration.TesseractVariablesの辞書を介して設定されます。 構成プロパティについては高度な読み取り設定ガイドを参照し、トリミングについては地域ガイドを参照してください。

インポート全体またはコンテナにかけて障害をトレースする方法は?

Send the explorer agent through the import history first, without writing
anything.

Last month's import read 3,000 scanned invoices, and finance found 45 totals
that do not match the paper. Reprocessing one of those invoices gives the same
wrong total every time.

Investigate:
1. Read ImportService.cs and find how pages are loaded and preprocessed.
2. Identify what the misread invoices have in common.
3. Explain the cause before changing anything.
4. Then propose the minimal fix, and how you will prove the 45 now read correctly.
Text

我々のテストでは、エクスプローラエージェントがインポーターがページを96 DPIでラスタライズし、合計が$0.00として記録されていることを発見しました。その後、エージェントは300 DPIですべての70の復元されたスキャンを再読み取りし、45の内43を復元しましたが、2つがゼロのままであり、1つの以前に正しいページが失敗しました。 エージェントは、最初の読み取りがゼロを返した場合のみ再試行を推奨しました。 DPI設定ガイドと信頼ガイドを参照してください。

Run this read-only until you have the cause.

This exception is thrown from InvoiceReader.ReadTotal in our Linux Docker
container but not on Windows:

[PASTE FULL EXCEPTION AND STACK TRACE HERE]

Check which IronOCR package the project references and whether it matches the
container's operating system, and whether IRONOCR_LICENSE_KEY reaches the
container. Explain the cause, then propose the change. Don't modify C# code
unless the cause is there.
Text

コンテナにはDockerガイドにリストされているネイティブ依存関係が必要です。 そのガイドでは、テストされたバージョンでWindowsネイティブバイナリのみを出荷するIronOcrをまだインストールしています。

一度限りのコードを再利用可能でテスト済みのコンポーネントに変えるにはどうすればよいですか?

Put the worker agent on this.

Refactor InvoiceReader and SearchablePdf into an InvoiceOcrService registered
with dependency injection. It should read totals and invoice numbers from
scanned PDFs, flag any value whose line confidence is below 80, and produce
searchable copies. Keep the preprocessing choices in one place. Add XML doc
comments. Keep it under 120 lines. Before you finish, run the service over
every folder in TestData/ that has an expected.csv and confirm each total
still matches.
Text
Write xUnit tests for InvoiceOcrService covering: every page in TestData/known/
returns its expected invoice number and total, a page without a total returns
null rather than a guess, a searchable copy has a text layer, and a missing
license key throws a clear exception. Assert on extracted values, not on the
full text of the page.
Text

欠落したキーのシナリオの場合は、IronOCRのライセンス例外がテストにアクセスできる公開型ではないため、自身のガードロジックをテストしてください。

定期的に公開されるIronOCRの質問をリポジトリスキルに保持し、OpenAIのカスタムプロンプトページが非推奨としてマークしている~/.codex/prompts/内には保持しません。

$ironocr Read the IronOCR API reference for OcrInput and list every method that corrects
image problems, such as rotation, noise, and low resolution, then show which
ones this project already calls.
Text

プロンプトが実運用で生成したものは何ですか?

上記のプロンプトをCodexに順番に送信し、サンプル請求書プロジェクトに対して実行しました。 プロジェクトは、スキャンされたPDFを持つコンソールアプリケーションで、オープンソースのTesseractラッパーを使用するレガシーサービスと、既知の値を持つ3セットのページを持っています。 実行後、独自のリリースビルド、テストスイート、および3セットすべてに渡るプローブによって、以下の結果が確認されました。

  • サプライヤー7の合計値は、DeskewとDeNoiseで6の9から9の9に上がりました。 単独で、Deskewは9分の9を読み取り、DeNoiseは9分の8を読み取りました。
  • レガシーリーダーとIronOCRの両方が、マイグレーションチェックで10の10に一致しました。
  • ドイツ語パックを使用すると、ドイツ語の合計が3の3で正しく読み取られ、サプライヤーセットは9の9のままでした。
  • 96行のサービスは、10の10の既知、3の3のドイツ語、9の9のサプライヤーを一致させ、80の信頼度以下の2つをフラグしました。
  • テストは13の13を通過しました。
  • Codexは、ビルドエラーや手動でのコード編集なしに15のうち14のプロンプトを実行しました。 コンテナプロンプトには実際のLinuxスタックトレースが必要で実行されておらず、ドイツ語のサンプルとインポート履歴はそれらのプロンプトの前に追加されました。
  • 以前の実行は3つの方法で失敗しました。 Codexは、どちらのエンジンも動作させずに10分の10のマイグレーションを報告し、リファクタリングで既知の合計が破損し、設定プロンプトがリーダーが使用していないフィルタを仮定しました。

この実行のCodexバージョン、モデル、タイミング、マシンは共有実行記録にあります。

次のプロジェクトに持ち越されるものは何ですか?

AIコーディングアシスタントガイドは、空のフォルダから測定結果にアシスタントを進めるための単一の受け入れプロンプトを追加し、同じプロンプトが私たちのテスト中のCodexで10の10を通過しました。


トラブルシューティング


質問ありますか?

質問がある場合は、support@ironsoftware.com にお問い合わせください。

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

もっと読む

準備はできましたか?

NuGetダウンロード数 6,394,824バージョン:2026.11ちょうどリリースされました