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

關於此包

方法ReadLicensePlate, ReadPassport, ReadPhoto, 和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屬性,包含有關檢測文字的有用資訊,例如RegionTextInRegion,和FrameNumber

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架構下運行,通過取消勾選專案設定中的"Prefer 32-bit"選項,以解決IronOCR在.NET Framework上高級掃描功能的問題。

IronOCR在語言支援方面有任何限制嗎?

IronOCR支援包括中文、日文、韓文和拉丁字母在內的多種語言。然而,ReadPassport方法目前僅支援英語文件。

我需要什麼來使用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擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

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天試用金鑰
無需信用卡或帳戶建立