如何使用IronOCR與Google Antigravity搭配
許多AI編碼工具只停留在程式碼編譯階段,讓您自己驗證程式碼是否有效。 在OCR中,這個缺口可能非常昂貴。 例如,發票匯入器可能會建置並填充資料庫而不出錯,但四分之一的總計數可能包含讀錯的數字,這是建置輸出無法揭示的。
Google Antigravity通過代理運作,將工作返回供您審查。 IronOCR能在.NET中從圖像和PDF中提取文字、條碼和表格。 當代理管理測試頁面時,它知道它們的內容,使用IronOCR讀取每個頁面,將提取的值與已知值進行比較,並重複進行直到它們匹配。
本文介紹了幫助您在IronOCR上構建軟體的AI編碼工具。 IronOCR對於照片和手寫的機器學習功能是另一個主題,有其自己的照片讀取指南和手寫指南。
快速開始在Antigravity中打開您的專案並指定預期的輸出。
/plan In this C# project, add IronOCR (the IronOcr NuGet package, namespace
IronOcr) and read the German invoice at TestData/rechnung.png, printing its text
and overall confidence. Only English ships with the package, so add whatever
German needs and tell me which package that was. Read the license key from the
IRONOCR_LICENSE_KEY environment variable, never hardcode it. Run dotnet build,
fix any errors, and show me the output.
計畫應該命名IronOcr.Languages.German和語言分配,省略任何一個都是錯誤。 沒有語言包,第一次讀取時會拋出LanguagePackException,因此錯誤立即顯示出來。
授權金鑰指南詳細說明了IronOCR檢查金鑰的所有位置。
最小工作流程(5 個步驟)
- 從NuGet下載C# OCR程式庫
- 在交給代理之前檢查專案是否編譯。
- 引用與主機匹配的平台套件,並從設置中載入金鑰。
- 給每個任務頁面提供應生成的語言、欄位和值。
- 審查實施計畫、差異和回傳的逐步指南。
什麼是Google Antigravity,它與聊天工具有何不同?
給予一個目標,Antigravity代理生成計畫,並在編輯器、終端和瀏覽器中實施,還以您可以檢視的Artifacts報告此過程而不是對話記錄檔。
沒有指引時,構建抓取管道的代理可能會選擇它找到的第一個OCR方法或猜測套件名稱。 猜測的名稱可能解決為攻擊者預先以該名稱發併的假冒品,這種做法稱作slopsquatting。 Windows使用IronOcr,而Linux使用IronOcr.Linux。
AI編碼助理指南列出了給代理的IronOCR文件連結,包括您可以在Antigravity中執行的單提示接受測試。
代理返回什麼,您如何審核?
在代碼之前,實施計劃
計畫定義了文件、語言選擇、篩選器和目標欄位。 審查以確認範圍。
在運行過程中,代碼差異
代碼差異顯示計劃的實施方式。 驗證讀者是否載入了指定的頁面,應用了承諾的篩選器,且每個使用的成員都在API參考中出現。
在運行後,進階導覽
逐步指南總結了更改並提供結果證據。
憑證從哪裡來?
/browser Services/CaptureService.cs extracts delivery note numbers and totals
from uploads to POST /capture.
1. Run the API and upload TestData/known/invoice-01.png in the browser.
Capture a screenshot.
2. Upload every file in TestData/known/ and record the delivery note number
and total returned.
3. Include the five rotated or noisy scans in that folder.
4. Report a table of file, expected delivery note number, number returned,
expected total, total returned, confidence, and match.
5. If any row does not match, explain the cause before changing anything, fix
it in CaptureService.cs, and run the whole table again. Attach the table
and the screenshots as Artifacts.
重複整個表之後確認為單次掃描添加的篩選器沒有破壞其他掃描。
從CLI,/browser命令啟動了Chrome子代理。
若要標記誤讀,如數字顛倒的總數,請在截圖上留言。
造成錯誤或缺失的OCR值的原因是什麼?
大多數不匹配是由幾個常見原因引起的。 指出懷疑的原因,代理就跳過試錯過程。
- 對於旋轉或噪音頁面上的錯誤數字,通常需要
Deskew和DeNoise。 - 返回文本但沒有條碼的讀取需要打開
Configuration.ReadBarCodes。 - 當
ConvertToSearchablePdf在掃描中拋出時,請改用SaveAsSearchablePdf處理讀取結果。
如何設置一個Antigravity可以工作的專案?
提供能夠編譯的專案給代理。 否則,代理將花時間在建置錯誤上。
將安裝工作委託給代理。
Add the IronOcr NuGet package to this project. Then tell me which version was
installed and show me the PackageReference line. Configure the license key to
be read from the IRONOCR_LICENSE_KEY environment variable or a config file
rather than hardcoded, and add that config file to .gitignore if it isn't
already. Don't change other package references.
在之後的所有任務中使用報告的版本號。
在專案初期將常設指令檔案AGENTS.md或GEMINI.md添加到儲存庫的根目錄中。 記錄OCR使用IronOCR。
/learn The repository already carries an AGENTS.md from the ChatGPT Codex
setup, and this platform reads the same file. Extend its OCR section with the
rules this platform adds. Produce an Implementation Plan before any file is
edited. Attach the evidence to the Walkthrough rather than describing it. And
treat no task as finished until every page read is checked against a known
value.
在我們的運行中,代理將三條規則添加到現有的指令檔中。
您如何委託提取和遷移工作?
當您需要欄位提取時,指定相關頁面和讀者所屬的文件。
Show me the Implementation Plan before any file is written. Then create
Services/DeliveryNoteReader.cs with a method that takes the path of a scanned
PDF, reads it with IronTesseract, and returns the amount on the line
containing Total due with that line's confidence, or null if the line is
missing. Create Services/SearchablePdf.cs with a method that writes a
searchable copy of a scanned PDF. Build, then prove ten sample invoices return
their known totals.
在我們的測試中,讀者將每次掃描加載為PDF輸入,並搜尋每頁的行以找到總計行。
遷移適合委託,因為它們過程冗長、重複且容易忽略邊緣情況。 將代理指向當前的源代碼。
/plan Read Capture/LegacyCaptureService.cs. It reads scans with another OCR
library.
1. List every read it performs, with the settings it uses.
2. Map each setting to its IronOCR equivalent, citing the documentation page.
3. Produce this as a plan Artifact. Do not write code yet.
桌面應用保存供您審查的計畫。 從CLI,審查計畫任務之後的差異。
沒有支持連結的任何映射應加以仔細審查。 圖像輸入指南和PDF輸入指南介紹載入過程,而結果指南則解釋輸出。
何時啟動更多代理?
OCR遷移可以分為兩個平行的任務。
Agent A: migrate Capture/LegacyCaptureService.cs to IronOCR per the approved
plan. Keep the public method signatures unchanged.
Agent B: write xUnit tests for the migrated service. Assert that every page in
TestData/known/ returns its expected delivery note number and total, that
barcodes are returned when enabled, that a page without a total returns null,
and that reads below 80 confidence are flagged. Do not assert on full page
text.
您如何調試在Linux、Docker或Azure上部署失敗?
Attach the terminal output to the Walkthrough when you are done. Reading
invoices works locally on Windows but fails in our Linux container with:
[PASTE FULL EXCEPTION AND STACK TRACE HERE]
Check which IronOCR package the project references, whether the container has
the native dependencies IronOCR needs, 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.
沒有明確的指令,代理可能會在catch區塊中抑制失敗。 指向它Docker指南和Azure指南。
在實際運行中,這些提示產生了什麼結果?
不需要粘貼失敗的七個提示在單個會話中,順序提交給Antigravity CLI對抗一個樣本抓取API。 該應用是一個ASP.NET Core應用,帶有傳統的Tesseract讀者,十張帶已知值的交貨單(包括三張旋轉的、兩張斑點的和四張帶QR碼的)、十張掃描的樣本發票和一張德國發票。授權金鑰通過環境變數提供。 執行後,一次獨立的建置,測試運行,和每張交貨單的驗證確認了以下結果。
- 已知的筆記在傳統讀者下與10個中的10個匹配,並且在遷移到IronOCR後與10個中的10個匹配,置信度為76.2到96.0。
- xUnit測試通過了17個中的17個。
- 在德國發票上,IronOCR以95.5的信心讀出的數字是3.271,07 EUR。
- 樣本發票總計數與10個中的10個匹配。
- 建構成功 7 次,共 7 次,0 錯誤且無人工編輯。
- 僅計畫提示仍然寫了代碼並報告了一個沒有任何人給予的批准。
- 條碼測試自動跳過條碼返回值為缺省的斑點QR筆記。
- 不同於頁面,會話無人操作運行在
--dangerously-skip-permissions下,且雙代理提示作為單個代理運行。
Antigravity的版本、模型和時間安排加上測試機在集線器的運行記錄中列出。
疑難排解
- 如果生成的代碼拋出LicensingException,則應在IronOCR中應用授權金鑰
- 如果從頁面讀取的值錯誤,則應改善OCR準確性
- 如果從返回文本的讀取中缺少條碼,則應使用IronOCR讀取條碼
- 如果在Linux容器中的讀取失敗但在本地正常運行,則應在Docker上使用IronOCR
問題?
如果您有任何疑問,請聯繫support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。