如何在Cursor中使用IronOCR
大多数由AI代理编写的IronOCR代码看起来正确且通常运行良好。 其中一些并不正常。 在未启用条形码收集的情况下读取条形码的代码将返回没有条形码。 在没有安装德语语言包的情况下将语言设置为德语的代码会引发LanguagePackException。 模型从其训练数据中写出,因此它快速,同时也容易出错,如这个细节。
Cursor是一个基于VS Code代码库构建的AI代码编辑器。 它可以读取您链接的文档并应用提交到您存储库的规则文件,因此其建议遵循IronOCR的API和您团队的惯例。 IronOCR是一个C#库,可以本地读取文本、条形码和表格结构。
每个清理过滤器既是输入的方法又是过滤器枚举中的一个值,名称本身并不能说明代码需要哪个。 这对于精确的更改最为重要,例如选择用于劣质扫描的滤镜、读取无文本层的PDF或保留表格结构。
使用IronOCR读取手写文本和照片的问题分别在手写指南和照片读取指南中进行了解决。
快速入门在C#项目中,发送此请求。
@Program.cs Read https://ironsoftware.com/ocr/csharp/llms-full.txt first.
In this C# project, read TestData/skewed-scan.png twice, once untouched and once
with a single correction filter applied to the input, and print both confidence
scores exactly as IronOCR returns them so I can compare them. Read the license
key from the IRONOCR_LICENSE_KEY environment variable and never print it. Use
only members that appear in the documentation.
许可证密钥指南展示了每种应用密钥的方法。
最小工作流程(5 个步骤)
- 从NuGet下载C# OCR库
- 提交一个包含IronOCR文档链接的文件夹范围的规则
- 在同一规则中命名IronOCR包,并在
Directory.Packages.props中保持其版本 - 将每个请求指向相关代码和样本扫描
- 编译并将提取的值与已知页面进行比较
您应该使用哪个Cursor模型进行OCR工作?
Composer是Cursor自己的代理模型。 模型选择器还提供Cursor共同开发的SpaceXAI的Grok模型,以及来自OpenAI,Anthropic,Google和其他实验室的模型。 下面的测试运行使用了Grok 4.7。
OCR工作的主要流程是添加一个过滤器、重建和重新读取样本的短周期,快速模型处理这些非常好。 当一批生产扫描由于没有明显原因返回错误字段时,切换到一个推理时间较长的慢速模型。
如何为Cursor提供IronOCR文档?
LLM的完整文本文件在一个URL中总结了145页的文档。 截至2026年10月,Cursor的@菜单附加了文件、文件夹、终端、聊天、Git差异和浏览器,因此IronOCR的文档通过链接到达代理。
Read https://ironsoftware.com/ocr/csharp/llms-full.txt
How do I read a scanned PDF and save a searchable copy, and how do I straighten
a slightly rotated page before reading it? Show the exact class and member names
from the documentation, and link the page you took them from.
如何编写加密您IronOCR惯例的项目规则?
项目规则存储在存储库根目录下的.cursor/rules文件夹中。 因为它们是与代码提交的,存储库的每个克隆都接收相同的集合。
规则是.mdc文件,用Markdown和YAML前言编写。 子文件夹也会被读取。 Cursor忽略此文件夹中的普通Markdown文件,因为该文件没有用于指明何时应用它的前言。 这可能是一个IronOCR规则包含的内容。
---
description: IronOCR conventions for scan reading in this project
globs: Imports/**/*.cs, Capture/**/*.cs
alwaysApply: false
---
# IronOCR conventions
- 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-full.txt
- Skill file with recipes: 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.
- Dispose OcrInput with a using block.
- Any language other than English needs its IronOcr.Languages package first.
Language packs keep their own version numbers, so pin the newest one on NuGet.
- Do not invent IronOCR API names. If a member is uncertain, say so and cite
the documentation instead of guessing.
仔细选择全局模式。 总是适用的规则附加到每个聊天会话,并使用额外的上下文,因此将IronOCR规则范围限定在包含OCR代码的文件夹中。
AGENTS.md。 它没有前言,因此没有全局模式,所以根文件适用于整个存储库。 为了限定其指令,请在它应覆盖的子目录中添加另一个。规则适用于Agent请求。 根据Cursor的文档,它们不会影响Tab自动完成,并且用户规则不适用于内联编辑。 自行检查那些功能的建议与规则。
如何将Tesseract设置映射到IronOCR?
比IronOCR代码更了解Tesseract命令行的模型可能会在IronOCR设置所在的位置写入Tesseract标志或变量名。
| 魔方 | IronOCR |
|---|---|
--psm 7 | Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine |
--oem 1 | 无需设置。 LSTM是唯一的引擎 |
-c tessedit_char_whitelist=... | Configuration.WhiteListCharacters |
其他 -c 变量 | Configuration.TesseractVariables |
-l eng+deu | AddSecondaryLanguage(OcrLanguage.German) |
--tessdata-dir, TESSDATA_PREFIX | UseCustomTesseractLanguageFile 针对一个 .traineddata 文件, Installation.LanguagePackDirectory 针对一个 .ocrdata 文件夹 |
IronOCR的过滤器向导需要同样的关注。 它测试过滤器组合并将最佳的作为C#代码返回,但该代码通过构造函数从文件路径构建输入,而编译器将其标记为过时。 向导也很慢。 在我们的测试机器上,一个200 DPI的页面几乎耗时九分钟,因此只运行在单个页面上。
规则中的两个条目涵盖两种情况。
- Configure Tesseract through IronTesseract.Configuration properties, never raw
tessedit_* variables or command-line flags. Use TesseractVariables only for a
setting with no named property.
- Rewrite OcrInputFilterWizard output from new OcrInput(path) to new OcrInput()
with LoadImage or LoadPdf before it reaches the codebase.
哪种模式适合这次更改?
Cursor提供了五种进行更改的方法。 将功能与工作的规模相匹配。
| 特征 | 此时使用它 | OCR示例 |
|---|---|---|
| Tab | 下一个编辑是可预测的 | 重复过滤器选项 |
| 内联编辑 | 一个文件,一句话 | 单个读者上的过滤器 |
| 代理 | 几个文件和一个构建循环 | 一个读者和打印它的作业 |
| 计划模式 | 事后审核太大 | 从Tesseract迁移 |
| 云代理 | 无人值守工作 | 已知页面测试 |
对于内联编辑,选择相关行,按Ctrl+K(macOS上为Cmd+K),并描述更改。 送货单上的条形码是一个代理更改。
@Imports/DeliveryNotes.cs @Imports/ImportJob.cs Read https://ironsoftware.com/ocr/csharp/skill.md first.
Also return every barcode and QR code on each delivery note, and have the notes
command print each one's format and value.
条形码仅在设置Configuration.ReadBarCodes并开始读取时才被收集。 它们与文本在同一结果中返回,因此一次读取涵盖了两者。 技能文件显示了该设置。
@提及对请求有什么帮助?
引用实际阅读文件比使用摘要更好,因为摘要可能遗漏重要细节。
@Imports/InvoiceReader.cs @TestData/warehouse/
InvoiceReader reads every scan in TestData/warehouse/ without an error, but about
a third of the totals have one wrong digit. Fix the input preparation, not the
parsing. Explain which setting caused it, and report how many totals match
expected.csv before and after.
如果您不确定哪些文件相关,请省略提及,代理将自行搜索代码库。
在您的背景中也包含样本扫描。 通过过滤器运行真实文件可以显示哪个组合可以修复它们。 在我们的仓库集合中,Deskew 单独读取了9个总计中的5个,DeNoise 单独读取了2个。修复需要两者按此顺序。 图像方向校正指南和图像质量校正指南涵盖了相关的滤镜。
如何计划和运行迁移到IronOCR的工作?
切换到计划模式,并发送此请求。
@Imports/ScanOcrService.cs
ScanOcrService reads scans with the Tesseract NuGet package. Plan a migration of
it to IronOCR.
List every read it performs, with the settings it uses (language, page
segmentation, preprocessing, region, output format), map each one to its IronOCR
equivalent, and name the files that change. Keep existing public method
signatures so callers don't change. If anything is ambiguous, choose and state
your assumption, and do not ask. Don't write code yet.
然后点击Build或发送下述请求给代理。
@Imports/ Implement the approved plan. Then run dotnet build, fix what breaks, confirm
every page in TestData/known/ still returns its expected values, and show me the
diff. Don't add new packages beyond IronOcr and any language packs the plan names.
云代理,原称为后台代理,需要付费计划,在云虚拟机中运行,并需要连接的存储库来处理您的代码。 在开始之前,将IRONOCR_LICENSE_KEY添加为云代理仪表板中的秘密。 迁移合并后开始测试。
@Imports/ @TestData/ Write xUnit tests for the migrated OCR service in a
tests/Imports.Tests project that Imports.csproj does not compile. Every page in
TestData/known/ returns its expected invoice number and total, a page without a
total returns null, DeliveryNotes returns the codes in TestData/notes/expected.csv,
and a read with OcrLanguage.French, whose language pack is not installed,
produces a clear error. The tests read the license key from IRONOCR_LICENSE_KEY
and never print it. Assert on extracted fields, never on full page text. Run
dotnet test and fix what fails.
AI编码助手指南运行一个完整的任务,并定义通过标准。
如何调试错误或缺失的OCR值?
@Imports/InvoiceReader.cs @Imports/DeliveryNotes.cs @TestData/returns/
Returned-goods invoices come back with a wrong digit in the total, and delivery
notes return no barcodes even though every note has one. Explain the cause of
each before changing anything, then fix both.
如果容器的异常在Cursor终端中,请将@Terminals也添加到下述请求中。
@Dockerfile @Imports.csproj Read https://ironsoftware.com/ocr/csharp/skill.md first.
Reads work on Windows but fail when this app runs in our Linux container. Check
which IronOCR package the project references, whether the container image has
the native dependencies IronOCR needs, and whether the license key reaches the
container. Explain the cause, then propose the change. Don't modify C# code
unless the cause is there.
在实际运行中这些提示生成了什么?
九个提示被顺序发送到Cursor,针对一个样本导入应用程序。它是一个带有集中包管理的控制台项目,IronOCR发票和送货单阅读器,Tesseract包装器上的扫描服务,以及已知值的扫描。 许可证密钥只在编辑器的环境中设置。 运行后,每个提交的新Release构建再次读取每个测试文件夹并重现以下数据。
- 仓库发票总计从修复前的9个中的6个到修复后的9个中的9个。
- 修复前没有送货单条形码返回。 之后,所有8个中的8个笔记都有它们的代码,并且没有额外的。
- 在退货分支上,发票总计从6个中的4个上升到6个中的6个,条形码从没有到6个中的6个。
- 偏斜扫描以87.79的置信度读取未更改,并在
Deskew后以96.41读取。 - 迁移后已知页面仍然读取10个中的10个和德语总计3个中的3个,如之前。
- xUnit套件通过了20个测试中的20个。
- 每个Release构建有0错误且无需手动编辑。 迁移设置了过时的
EngineMode,留下了两个CS0618警告。 - 容器答案命名了
IronOcr.Linux,Docker指南的apt包和缺失的密钥,并且没有更改任何C#文件。 - 一些步骤与本页不同。 提示由桌面应用程序手动发送,计划通过发送下一个提示获得批准,Build从未点击过,云代理提示本地运行。 提示八最初错误发送到较早的聊天,并被重置和重新发送。 机器上没有Docker,容器提示通过其解释和建议进行判断。
运行记录列出了该指南以及其他指南的版本、时间和测试机器。
故障排除
- 如果生成的代码抛出许可异常,请在IronOCR中应用许可证密钥
- 如果读取返回文本但没有条形码,请用IronOCR读取条形码
- 如果读取的值与扫描不匹配,请提高OCR准确度
- 如果在本地读取正常但在Linux容器中失败,请在Docker上使用IronOCR
有问题吗?
如果您有任何问题,请联系support@ironsoftware.com
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。