如何使用IronOCR与Google Antigravity

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

许多AI编码工具在代码编译后停止,让您自行验证代码是否有效。 在OCR中,这种差距可能代价高昂。 例如,发票导入器可能会建立并填写数据库而没有错误,但总计数的四分之一可能包含误读数字,这在构建输出中不会显露。

Google Antigravity通过返回工作供您审查的代理来运作。 IronOCR在.NET中本地从图像和PDF中提取文本、条码和表格。 当代理管理测试页面时,它知道其内容,通过IronOCR读取每个页面,将提取值与已知值进行比较,并反复进行直到匹配为止。

本文涵盖了帮助您在IronOCR上构建软件的AI编码工具。 IronOCR自身的用于照片和手写的机器学习功能是一个单独的话题,有其自己的照片阅读指南和手写指南。

快速入门
NuGet使用NuGet安装

PM > Install-Package IronOcr

通过在 NuGet 包管理器控制台中运行上述命令安装 IronOCR,或在 NuGet 包管理器中搜索该包。

在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.
Text

计划应该命名IronOcr.Languages.German和语言分配,省略其中任何一个都是错误。 没有语言包,第一次读取会抛出一个LanguagePackException,所以错误立刻显现出来。

许可证密钥指南详细说明了IronOCR检查密钥的所有位置。



什么是Google Antigravity,它与聊天工具有何不同?

给定一个目标,Antigravity代理生成计划,在编辑器、终端和浏览器中执行它,并通过您可以审查的文物而不是聊天记录报告其所做的内容。

如果没有指导,构建捕获管道的代理可能会选择它发现的第一个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.
Text

随后重复整个表格,确认为一次扫描添加的滤镜没有破坏其他的。

从CLI中,/browser命令启动了一个Chrome子代理。

请注意: 查看Antigravity生成的屏幕截图和任何浏览器记录。 如果代理跳过了上传表单,则没有测试用户工作流程。

要标记误读,例如总计数的数字颠倒了,请在屏幕截图上发表评论。

导致错误或缺失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.
Text

在所有后续任务中使用报告的版本号。

在项目早期阶段,向存储库根目录添加一个固定的指令文件,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.
Text

在我们的运行中,代理将三条规则添加到了现有指令文件中。

如何委派提取和迁移工作?

当您需要字段提取时,请指定相关页面和读取器所属的文件。

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.
Text

在我们的测试中,读取器将每个扫描作为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.
Text

桌面应用程序包含供您审查的计划。 从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.
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.
Text

如果没有明确的指令,代理可能会在一个catch块中抑制失败。 指向Docker指南和Azure指南。

在实际运行中这些提示生成了什么?

不需要粘贴失败的七个提示被顺序提交到Antigravity CLI,单次会话中针对示例捕获API。 该应用程序是一个ASP.NET Core应用程序,具有一个传统的Tesseract读取器、十个具有已知值的交付便条(包括三个旋转的、两个有斑点的和四个带有二维码的)、十个扫描的示例发票和一个德文发票。许可证密钥通过环境变量提供。 执行后,一个独立的构建、测试运行和每个交付便条的验证确认了以下结果。

  • 已知便条与传统阅读器匹配10/10,迁移到IronOCR后匹配10/10,置信度76.2到96.0。
  • xUnit测试通过率17/17。
  • 在德文发票上,IronOCR以95.5置信度读取3.271,07欧元。
  • 示例发票总计数匹配10/10。
  • 构建成功7次,共7次,0错误,并且没有人工编辑。
  • 仅提示计划写了代码并报告了无人批准。
  • 条形码测试静默跳过了返回无条形码的有斑点的QR便条。
  • 不同于页面,会话在无人值守的情况下运行--dangerously-skip-permissions,两个代理提示作为一个代理运行。

Antigravity 的版本、模型和时序,加上测试机器,列在中心的运行记录中。


故障排除


有问题吗?

如果您有任何问题,请联系support@ironsoftware.com

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

阅读更多

准备开始了吗?

NuGet 下载量 6,394,824版本:2026.11刚刚发布