GitHub CopilotでのIronOCRの使用方法

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

.NETチームは、文書キャプチャ、買掛金、請求処理、または記録管理のために確立されたVisual Studioソリューションを使用しているため、GitHub Copilotを評価するためにエディタを変更する必要はありません。これは、既存のワークフローをサポートします。

Copilotは、Visual Studio、VS Code、JetBrains IDE、およびGitHub.comで実行されます。 IronOCRは.NETでローカルに認識処理を行います。

写真や手書きのためのIronOCRのモデルに関する詳細は、写真読取案内および手書き案内を参照してください。

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

PM > Install-Package IronOcr

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

現在のIDEで、メソッドが返さなければならないものや、モデルが召喚しなければならないデフォルトを入力します。

Add a ReadDeliveryNote method to Imports/DeliveryNotes.cs that uses IronOCR (the
IronOcr NuGet package, namespace IronOcr) to read a scanned delivery note and
return both its text and the barcode values found in the same pass. Barcode
reading is off by default, so switch it on before the read. Take the license key
from the IRONOCR_LICENSE_KEY environment variable, never inline. Then build and
fix any errors.
Text

エディタが開始する環境でIRONOCR_LICENSE_KEYを設定し、キーを保持する他の場所についてはライセンスキー案内を参照してください。 それなしでは、最初の読み取りがライセンスチェックで停止し、Copilotは自動生成したOCRコードを実行できません。



Visual Studioですでに進行中のプロジェクトにCopilotをどのように組み込むのですか?

1ファイルのIronOCR変更にはインラインチャットを使用してください。 変更が複数のファイルにわたる場合はエージェントモードに切り替えてください。これにより、プロジェクトをビルドし、OCRコードを実行できます。 GitHubのクラウドエージェントは、割り当てられた業務を受け取り、プルリクエストを返します。

CopilotでIronOCRの規約を設定する方法

IronOCRの規約を.github/copilot-instructions.mdとしてコミットします。これは、Copilot Chat、エージェントモード、およびクラウドエージェントが読み取ります。 インライン補完はこれを無視します。

# Copilot instructions

## OCR

- Use IronOCR for all OCR work. The NuGet package is IronOcr on Windows and
  IronOcr.Linux on Linux and Docker. The namespace is IronOcr. Do not add
  another OCR engine or a cloud OCR service.
- Documentation: https://ironsoftware.com/ocr/csharp/llms.txt
  Skill file: https://ironsoftware.com/ocr/csharp/skill.md
- Target the IronOcr version pinned in Directory.Packages.props. Do not upgrade
  it as part of an unrelated change.
- Never inline a license key. Read it from configuration or the
  IRONOCR_LICENSE_KEY environment variable.
- Always dispose OcrInput with a using block.
- Barcode reading is off by default. Set Configuration.ReadBarCodes only where needed.
- Apply only the image filters that fix a visible defect.
- Do not invent IronOCR API names. If a member is uncertain, say so and cite
  the documentation rather than guessing.

## Testing

- Every OCR change must be run against pages with known values.
- Assert on extracted fields. Never assert on the full text of a page.

## Pull requests

- Say which IronOCR APIs the change introduces, and link the page for each.
- If the OCR tests fail, check the runner environment before changing code
  that the issue did not ask you to touch.
Markdown

1つのフォルダーに独自のOCR言語規則を与える方法

IronOCRの設定はソースによって異なることが多いです。例えば、ドイツの仕入先の請求書や英語の倉庫スキャン。 ドイツ語の規則を.github/instructions/ocr-german.instructions.mdに入れてください。 Copilotは、作業中のファイルがドイツ文件の上部にあるパスパターンに一致する場合、そのファイルとリポジトリ全体のものを適用します。

---
applyTo: "Imports/De/**"
---

- Invoices in this folder are German. Set Language = OcrLanguage.German and add
  English with AddSecondaryLanguage(OcrLanguage.English) for supplier names.
- German comes from the IronOcr.Languages.German NuGet package. Language packs
  keep their own version numbers, so never align this one with IronOcr.
- Amounts use German formatting, such as 1.234,56. Parse them with the de-DE culture.
Markdown

最新のドイツパック2020.11.2と英語をセカンダリ言語として読み取ったドイツサンプルは、その行で96.6の信頼度で「Gesamtbetrag: 3.271,07 EUR」と返されました。

クラウドエージェントが行動できる問題を作成するにはどうすれば良いですか?

誤った請求金額のみを報告する問題は、クラウドエージェントに原因となるファイル、影響を受けたスキャン、および正しい金額を見つけさせます。

Title: Totals misread on rotated scans from the warehouse scanner

**Files:** Imports/InvoiceReader.cs, Imports/ImportJob.cs
**IronOcr version:** as pinned in Directory.Packages.props
**Framework:** .NET 8

**Expected:** Every invoice in TestData/warehouse/ returns the total recorded in
TestData/warehouse/expected.csv, with line confidence of at least 80.

**Actual:** About a third of warehouse scans return totals with one wrong digit.
The pages are rotated a few degrees and have speckle. Invoices from the email
inbox read correctly. No exception is thrown.

**Constraints:** Keep the Total due parsing as it is. Do not change the public
signature of InvoiceReader.ReadTotal. No new packages.

**Acceptance:** Existing tests pass, plus a new test that reads every scan in
TestData/warehouse/ and matches expected.csv.
Markdown

メールで送信された請求書が正しく読み取れたことを示すメモは、解析ではなくスキャン品質への調査を指示します。

なぜクラウドエージェントのテストがIronOCRプロジェクトで失敗するのですか?

デフォルトでは、クラウドエージェントは一時的なUbuntu Linuxランナーでビルドとテストを行います。 パッケージIronOcrはWindowsネイティブランタイムのみを提供するため、ランナーにはIronOcr.Linuxが必要です。 ワークフローの設定は.github/workflows/copilot-setup-steps.ymlにあり、その1つのジョブはcopilot-setup-stepsと名付けられており、デフォルトブランチにマージされると、そのギャップを埋めます。

Write .github/workflows/copilot-setup-steps.yml for this repository.

The job must be named copilot-setup-steps exactly, or it is ignored. Trigger it
manually, and on push and pull request limited to that one file path.

Run it on ubuntu-latest with read access to repository contents. Check out the
repository, set up the .NET SDK for the version this project targets, install
the native dependencies IronOCR needs on Ubuntu, then restore packages.

For those dependencies read
https://ironsoftware.com/ocr/csharp/get-started/linux/ and use what it lists for
Ubuntu rather than a list from memory. Note in a comment that the list can
change between releases.

The runner is Linux, so OCR there needs the IronOcr.Linux package this
repository's instructions name. Show me the finished YAML, then any project
change the runner still needs to restore IronOcr.Linux.
Text
  • ライセンスキー: クラウドエージェントは、Actions、Codespaces、Dependabotの秘密を読み取れないため、キーはAgentsの秘密に必要です。 設定の下でキーを追加し、次に秘密と変数、次にエージェントを選択し、エディタが読み取るのと同じ名前で、エージェントが環境変数として受け取ります。
  • セットアップステップの失敗: クラウドエージェントを停止しません。 エージェントは残りのステップをスキップし、とにかく作業を開始するので、アクションタブからワークフローを1回実行し、成功することを確認してください。

マージする前に何を確認すべきですか?

Copilotのプルリクエストは、同僚のプルリクエストのようにレビューしてください。

/tests Add xUnit tests for this change: every scan in TestData/warehouse/ returns
the invoice number and total in its expected.csv, a page without a total returns
null rather than a guess, and reads below 80 confidence are flagged. Assert on
extracted fields, not on the full page text.
Text

新しいIronOCRのリリースは、値を変更せずに、スペースと改行を変更することがあります。 AIコーディングアシスタントのガイドは、このレビューを再現可能なテストに変えます。

誤ったOCR結果を診断する方法

誤った結果は通常、3つの原因のいずれかを持っています。 ページは画像フィルターやより高いDPIが必要であり、ドキュメントの言語パックが追加されていないか、読み取りが誤った領域を対象にしています。 空のバーコードコレクションは、Configuration.ReadBarCodesが設定されていなかったことを意味することもあります。

Delivery notes in TestData/notes/ return their text, but about a third
come back with an empty barcode collection, while the same notes decode fine on
the handheld scanner.

Explain the cause before changing anything, then fix it in ReadDeliveryNote only.
Do not change the text extraction. Report how many notes return a barcode before
and after. Measure the current count first and base the explanation on what you
measured, not on a guess.
Text

計測ファーストの指示がない実行では、Copilotは最初に解像度を非難し、次に欠落したバーコードをQRコードに関連付けて追跡し、特定の領域をクロップし、灰色の1つのシェードを選択することでそれらを復元しました。 ページの下部に印刷されたかすれたコードのある2番目のセットでは、その修正でどれも読み取れませんでした。 指示で、Copilotは最初に計測し、コントラスト、二値化、拡大、クロップを排除し、シャープ化フィルターを適用した後、2度目の読み取りを追加しました。 Copilotが以前に見たことのないページで常に修正をテストしてください。

ローカルでの認識が機能するが、ランナーまたはコンテナで失敗する場合は、Copilotに概要ではなく完全な例外メッセージを提供してください。

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

このガイド内のすべてのプロンプトは、エディタで連続して送信されました。これは、サンプル受信アプリ、.NET 9コンソールプロジェクト、集中パッケージ管理、請求書リーダーと既知の値を持つスキャンに対して実行されました。 以下の各結果は、チャットの外で再度測定されました。

  • バーコード付き配送メモは、修正前の6つのうち9つから、修正後の9つのうち9つまで、同じ修正で第2セットの12のうち8つのかすれたコードを読み取りました。
  • /testsスイートは14のうち14が合格しました。また、ImportJobのコンソール出力を要求なしで変更し、構築されたレコードで信頼度閾値をテストしました。
  • すべてのプロンプトの後でReleaseビルドはクリーンで、手作業の編集なしでした。
  • 2つの部分がページからのものとは異なりました。 テストプロンプトにライセンスキーを貼り付け、Copilotはそれをすべてのファイルから除外しました。設定ワークフロー、クラウドエージェント、その問題、エージェントの秘密はGitHub ActionsまたはGitHubリポジトリを必要とするため、どれも実行されませんでした。

これらの数字の背後にあるアシスタントのバージョン、モデル、タイミング、テストマシンは、実行記録の他のすべてのガイドと共に記載されています。


トラブルシューティング


質問ありますか?

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

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

もっと読む

準備はできましたか?

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