如何使用IronOCR與GitHub Copilot
.NET團隊已經有Visual Studio解決方案,用於文件擷取、應付帳款、索賠處理或記錄管理,不需要更換編輯器來評估GitHub Copilot,因為它支持現有的工作流程。
Copilot在Visual Studio、VS Code、JetBrains IDE和GitHub.com運行。 IronOCR在.NET中本地處理識別。
有關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.
在編輯器啟動的環境中設置IRONOCR_LICENSE_KEY,其他放置金鑰的地方請參閱授權密鑰指南。 沒有它,第一次讀取會停在授權檢查,Copilot不能運行它撰寫的OCR代碼。
最小工作流程(5 個步驟)
- 從NuGet下載C# OCR程式庫
- 在
.github/copilot-instructions.md中檢查您的IronOCR慣例 - 對單個文件使用內嵌聊天,涉及多個文件時使用代理模式
- 當雲端代理單獨工作時,寫一個詳細的問題
- 使用API參考確認每一個IronOCR成員在拉取請求中
Copilot 如何融入已在 Visual Studio 的項目中?
對單文件IronOCR更改使用內嵌聊天。 當更改涉及多個文件時切換到代理模式,因為它可以構建項目並自行運行OCR代碼。 GitHub 上的雲代理會接受指定的議題並返回一個 pull request。
如何為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.
如何給一個文件夾設置自己的OCR語言規則?
IronOCR設置通常根據來源不同,如德國供應商發票和英國倉庫掃描。 將德文規則放在.github/instructions/ocr-german.instructions.md中。 Every prompt in this guide that runs in the editor was sent in sequence, over two chats, against a sample receiving app, a .NET 9 console project with central package management, an invoice reader and scans with known values.
---
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.
一個使用最新的德語包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.
電郵發票讀取正確的說明將調查方向引導向掃描質量而非解析。
為何雲端代理的測試在IronOCR專案上失敗?
默認情況下,雲端代理在暫時的Ubuntu Linux執行者上構建和測試。 IronOcr 套件僅提供Windows本地運行時,因此執行者需要IronOcr.Linux。 在.github/workflows/copilot-setup-steps.yml的設置工作流程,具有一個命名為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.
- 授權密鑰:雲端代理無法讀取Actions、Codespaces或Dependabot密碼,因此密鑰需要一個Agents密碼。 在設定、然後是密碼和變數、然後是Agents下新增密鑰,使用編輯器讀取的相同名稱,代理作為環境變數接收它。
- 設置步驟失敗:它不會停止雲端代理。 代理跳過剩餘步驟並開始工作,無論如何,從Actions標籤運行工作流程一次並確認它通過。
合併之前應檢查什麼?
像對待同事一樣審查一個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.
新版本的IronOCR可以在不改變值的情況下改變間距和行距。 AI編碼助手指南將此審查轉化為可重複的測試。
如何診斷錯誤的OCR結果?
錯誤結果通常有三個成因之一。 頁面需要一個圖像濾鏡或一個更高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.
在沒有先量度的指示下運行,Copilot起初歸咎於解析度,然後追溯缺失的條形碼到淡灰色打印的QR碼,通過裁剪固定區域並選擇一個灰色陰影恢復它們。 在第二組中,頁面打印得低的淡碼,這個修正沒有讀取到任何一個。 With the instruction, Copilot measured first, ruled out contrast, binarization, upscaling, and cropping, and added a second read after applying a sharpening filter. 在Copilot未曾見過的頁面上測試修正。
如果本地識別工作但在執行者或容器中失敗,請給Copilot完整的例外信息而非摘要。
在實際運行中,這些提示產生了什麼結果?
本指南中運行於編輯器的每個提示都是依次發送的,通過兩次聊天,針對一個接收樣本的應用程序、一個.NET 9控制專案中,帶有中央包管理、一個發票閱讀器和已知值的掃描。 每個結果都再次在聊天之外測量。
- 帶條形碼的送貨單從修正前的9中的6個到修正後的9個,且相同的修正在第二組中讀取了12個中的8個淡色碼。
/tests套件通過了14個中的14個。未經請求還改變了ImportJob的控制台輸出,並在構造記錄而非掃描上測試了信心水準。- All four prompts resulted in a clean Release build without hand edits.
- 頁面上有兩部分運行不同。 該人將許可密碼粘貼到測試提示中,Copilot將其排除於每個文件。安裝工作流程、雲端代理、其問題和Agents密碼需要GitHub Actions或GitHub存儲庫,因此它們都未運行。
這些數字背後的助手版本、模型、計時和測試機器列示在運行記錄的每個其他指南中。
疑難排解
- 在IronOCR中應用授權密鑰如果拉取請求生成,但第一次讀取引發了授權例外
- IronOCR在Linux上如果Linux運行器缺少本地依賴關係
- 提高OCR準確性如果提取的值與掃描結果不同
- IronOCR運行時目錄如果缺少本機文件從生成輸出
問題?
如果您有任何疑問,請聯繫support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。