IRONSOFTWAREHOME

How to Read Specialized Documents with C# and IronOCR

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

用单一的通用方法准确解读标准文本文件、车牌、护照和照片等特定文件是非常困难的。 这些挑战源于每种文档类型的格式、布局和内容的多样性,以及图像质量、失真和专业内容的差异。 此外,随着文档类型范围的扩大,实现上下文理解以及平衡性能和效率变得更加复杂。

IronOCR 引入了针对特定文档(例如标准文本文件、车牌、护照和照片)执行 OCR 的具体方法,以实现最佳的准确性和性能。

快速开始:一行代码读取护照

使用IronOCR的ReadPassport扩展以最小设置提取所有关键护照详细信息。只需一行代码—假设您已经安装了IronOCR和AdvancedScan—您将快速轻松地获得结构化结果数据,例如名称、护照号码、国家等。

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2复制并运行这段代码。

    var result = new IronTesseract().ReadPassport(new OcrInput().LoadImage("passport.jpg"));
    C#
  3. 3部署到您的生产环境中进行测试

    通过免费试用立即在您的项目中开始使用IronOCR
    arrow pointer

关于包裹

ReadScreenShot方法是IronOCR基本包的扩展方法,需要安装IronOcr.Extensions.AdvancedScan包。

这些方法适用于OCR引擎配置,如黑名单和白名单。支持多种语言,包括中文、日文、韩文和拉丁字母表,但ReadPassport方法例外。 请注意,每种语言都需要额外的语言包IronOcr.Languages

在 .NET Framework 上使用高级扫描功能需要项目在 x64 架构上运行。 进入项目配置,取消选中"首选 32 位"选项即可实现此目的。 请参阅以下故障排除指南了解更多信息:". NET Framework 高级扫描"。

阅读文档示例

ReadDocument方法是一个强大的文档阅读方法,专注于扫描文档或包含大量文字的纸质文档照片。 PageSegmentationMode配置对于读取不同布局的文本文件非常重要。

例如, SingleBlockSparseText类型可以从表格布局中检索大量信息。 这是因为SingleBlock假定文本保持为一个块,而SparseText假定文本分散在整个文档中。

using IronOcr;
using System;

// Instantiate OCR engine
var ocr = new IronTesseract();

// Configure OCR engine
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;

using var input = new OcrInput();

input.LoadPdf("Five.pdf");

// Perform OCR
OcrResult result = ocr.ReadDocument(input);

Console.WriteLine(result.Text);

以下方法是对基本 IronOCR 包的扩展方法,需要安装IronOcr.Extensions.AdvancedScan包。

读取车牌示例

ReadLicensePlate方法对从照片中读取车牌进行了优化。 此方法返回的特殊信息是Licenseplate属性,其中包含所提供文档中车牌位置的信息。

using IronOcr;
using IronSoftware.Drawing;
using System;

// Instantiate OCR engine
var ocr = new IronTesseract();

using var inputLicensePlate = new OcrInput();

inputLicensePlate.LoadImage("LicensePlate.jpeg");

// Perform OCR
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);

// Retrieve license plate coordinates
Rectangle rectangle = result.Licenseplate;

// Retrieve license plate value
string output = result.Text;

阅读护照示例

ReadPassport方法通过扫描机器可读区(MRZ)内容,优化护照信息的读取和提取。 MRZ 是护照、身份证和签证等官方文件中特别定义的区域。 MRZ 通常包含重要的个人信息,例如持有人的姓名、出生日期、国籍和证件号码。 目前,此方法仅支持英语。

using IronOcr;
using System;

// Instantiate OCR engine
var ocr = new IronTesseract();

using var inputPassport = new OcrInput();

inputPassport.LoadImage("Passport.jpg");

// Perform OCR
OcrPassportResult result = ocr.ReadPassport(inputPassport);

// Output passport information
Console.WriteLine(result.PassportInfo.GivenNames);
Console.WriteLine(result.PassportInfo.Country);
Console.WriteLine(result.PassportInfo.PassportNumber);
Console.WriteLine(result.PassportInfo.Surname);
Console.WriteLine(result.PassportInfo.DateOfBirth);
Console.WriteLine(result.PassportInfo.DateOfExpiry);

结果

读取护照

请确保文件中仅包含护照照片。 任何页眉和页脚文本都可能干扰该方法,并导致意外的输出。

查看照片示例

ReadPhoto方法对读取包含难以辨认的文本的图像进行了优化。 此方法返回TextRegions属性,其中包含有关检测到的文本的有用信息,例如RegionTextInRegionFrameNumber

using IronOcr;
using IronSoftware.Drawing;

// Instantiate OCR engine
var ocr = new IronTesseract();

using var inputPhoto = new OcrInput();
inputPhoto.LoadImageFrame("photo.tif", 2);

// Perform OCR
OcrPhotoResult result = ocr.ReadPhoto(inputPhoto);

// index number refer to region order in the page
int number = result.TextRegions[0].PageNumber;
string textinregion = result.TextRegions[0].TextInRegion;
Rectangle region = result.TextRegions[0].Region;

阅读屏幕截图示例

ReadScreenShot方法对读取包含难以辨认文本的截图进行了优化。 与 ReadPhoto 方法类似,它也返回TextRegions属性。

using IronOcr;
using System;
using System.Linq;

// Instantiate OCR engine
var ocr = new IronTesseract();

using var inputScreenshot = new OcrInput();
inputScreenshot.LoadImage("screenshot.png");

// Perform OCR
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);

// Output screenshoot information
Console.WriteLine(result.Text);
Console.WriteLine(result.TextRegions.First().Region.X);
Console.WriteLine(result.TextRegions.Last().Region.Width);
Console.WriteLine(result.Confidence);

常见问题解答

如何使用 OCR 在 C# 中读取车牌?

您可以使用 IronOCR 提供的 ReadLicensePlate 方法从照片中准确读取车牌。此方法返回车牌文本及其位置信息。

提取护照照片信息的最佳方法是什么?

IronOCR 的 ReadPassport 方法专为扫描护照照片中的可机读区 (MRZ) 设计,提取重要信息,如姓名、出生日期和证件号码。

IronOCR 可以读取含有难读文本的照片中文本吗?

可以,IronOCR 中的 ReadPhoto 方法针对读取难读文本的图像进行了优化,提供有关检测文本及其区域的详细数据。

可以使用 IronOCR 从截图中读取文本吗?

当然可以,IronOCR 的 ReadScreenShot 方法专为处理截图文本进行了优化,并提供详细的文本区域信息。

如何提高复杂布局文件的 OCR 准确性?

要提高复杂布局文档的 OCR 准确性,请配置 IronOCR 中的 PageSegmentationMode。如 SingleBlock 和 SparseText 等选项对于从表格布局中提取信息特别有用。

如果 IronOCR 的高级扫描功能在我的 .NET Framework 项目中不起作用,我该怎么办?

确保您的项目设置为在 x64 架构上运行,方法是取消选中项目设置中的“首选 32 位”选项,以解决 IronOCR 在 .NET Framework 上使用高级扫描功能的问题。

IronOCR 有语言支持限制吗?

IronOCR 支持多种语言,包括中文、日语、韩语和拉丁字母。不过,ReadPassport 方法目前仅支持英语文件。

using IronOCR 的高级扫描功能需要什么?

要使用 IronOCR 的高级扫描功能,需要 IronOcr.Extensions.AdvancedScan 包,该包仅在 Windows 上可用。

What precautions should be taken when using the `ReadPassport` method?

When using the `ReadPassport` method, ensure that the image only contains the passport photo to avoid confusion and unexpected output. Any additional text like headers and footers should be excluded.

How can IronOCR be installed to perform document reading in C#?

IronOCR can be installed via the NuGet package manager. Ensure that both IronOCR and IronOcr.Extensions.AdvancedScan are installed to utilize methods for reading specialized document types like license plates and passports.

Curtis Chau
技术作家

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

...
阅读更多

准备开始了吗?

Nuget Downloads 6,236,385版本:2026.9刚刚发布

免费获取

30天试用密钥 即刻获取。

bullet_checked无需信用卡或创建账户
bullet_test在生产环境中测试
且无水印
bullet_calendar30天完全
功能性产品
bullet_support试用期间提供
24/5技术支持
立即获取您的免费30 天试用密钥
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索"IronOCR"
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

或在这里下载Windows安装程序。

  1. 下载并解压IronOCR到你的解决方案目录中的~/Libs位置
  2. 在Visual Studio解决方案资源管理器中,右键点击引用。选择浏览,“IronOCR.dll”

许可证售价$999

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户