A PHP Error was encountered
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: libraries/StructuredData.php
Line Number: 638
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 638
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1302
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'name'
Filename: libraries/StructuredData.php
Line Number: 641
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 641
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1302
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'title'
Filename: libraries/StructuredData.php
Line Number: 643
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 643
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1302
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'comment'
Filename: libraries/StructuredData.php
Line Number: 644
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 644
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1302
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: libraries/StructuredData.php
Line Number: 638
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 638
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 815
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1305
Function: buildHowToSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'name'
Filename: libraries/StructuredData.php
Line Number: 641
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 641
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 815
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1305
Function: buildHowToSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'title'
Filename: libraries/StructuredData.php
Line Number: 643
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 643
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 815
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1305
Function: buildHowToSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'comment'
Filename: libraries/StructuredData.php
Line Number: 644
Backtrace:
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 644
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1285
Function: getWebPageContributor
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 815
Function: buildSingleDocArticleSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1305
Function: buildHowToSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 1317
Function: buildBaseDocumentationSchema
File: /var/www/ironpdf.com/application/libraries/StructuredData.php
Line: 2699
Function: buildTechArticleSchema
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 354
Function: setJsonLDStructuredData
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
IronOCR
操作指南
閱讀護照
How to Extract Passport Data with IronOCR
View the article in
English
在包括機場的櫃檯值機和安全移民等應用程序和系統中,代理每天必須處理大量護照,擁有一個能夠準確提取旅客關鍵任務信息的可靠系統是確保通過移民的高效和流暢流程的關鍵。
快速入門:一行代碼提取護照 MRZ 資料
在幾秒鐘內開始讀取護照:這個示例展示了如何輕鬆地使用 OcrInput 加載護照圖像,使用 ReadPassport() 提取數據,然後訪問返回的 PassportInfo 的結構化字段如姓名、編號和日期。 沒有繁瑣的設置——只需一行簡單的代碼。
Get started making PDFs with NuGet now:
Install IronOCR with NuGet Package Manager
Copy and run this code snippet.
var passportInfo = new IronOcr.IronTesseract().ReadPassport(new IronOcr.OcrInput("passport.jpg")).PassportInfo;
Deploy to test on your live environment
Start using IronOCR in your project today with a free trial
class="hsg-featured-snippet">
簡化工作流程(5 步)
下載 C# 庫來讀取護照
導入護照圖像以便讀取
確保文檔僅包含護照圖像,無標題或頁腳
使用 ReadPassport 方法從圖像中提取數據
訪問 OcrPassportResult 屬性以查看並進一步處理提取的護照數據
護照數據提取示例
例如,我們將使用護照圖像作為輸入來展示 IronOCR 的功能。 加載圖像後,您可以利用 ReadPassport 方法來識別並提取護照中的信息。 此方法返回一個 OcrPassportResult 對象,其中包含如 GivenNames、Country、PassportNumber、Surname、DateOfBirth 和 DateOfExpiry 等屬性。 所有 PassportInfo 對象的成員都是字符串。
該方法目前僅適用於基於英語的護照。
在 .NET Framework 上使用高級掃描需要項目在 x64 架構上運行。
對於 Mac 用戶,請注意,ReadPassport 方法目前不會自動旋轉輸入。 在使用輸入時,請確保 MRZ 始終位於文件底部,否則該過程將失敗。
護照輸入
class="content-img-align-center">
class="center-image-wrapper">
代碼
:path=/static-assets/ocr/content-code-examples/how-to/read-passport-read-passport.cs
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);
Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPassport = New OcrInput()
inputPassport.LoadImage("passport.jpg")
' Perform OCR
Dim result As OcrPassportResult = 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)
$vbLabelText
$csharpLabel
輸出
class="content-img-align-center">
class="center-image-wrapper">
然後我們訪問從 OcrPassportResult 對象獲得的 PassportInfo 數據成員。
GivenNames:PassportInfo 的一個屬性,返回護照輸入的名的字符串。 這對應於第一個 MRZ 數據行,位置從 4 到 44。
Country:PassportInfo 的一個屬性,返回護照輸入的國家信息作為字符串。 這對應於第一個 MRZ 數據行,位置從 2 到 3。返回的字符串將拼寫出簽發國的全名而不是縮寫。 在我們的示例中,美國返回 'United States of America'。
PassportNumber:PassportInfo 的一個屬性,返回護照輸入的護照號碼作為字符串。 這對應於第二個 MRZ 數據行,位置從 1 到 9。
Surname:PassportInfo 的一個屬性,返回護照輸入的姓作為字符串。 這對應於第一個 MRZ 數據行,位置從 4 到 44。
DateOfBirth:PassportInfo 的一個屬性,返回護照輸入的出生日期作為 YYYY-MM-DD 格式的字符串。 這對應於第二個 MRZ 數據行,位置從 14 到 19。
DateOfExpiry:PassportInfo 的一個成員屬性,返回護照輸入的有效期作為 YYYY-MM-DD 格式的字符串。 這對應於第二個 MRZ 數據行,位置從 22 到 27。
理解 MRZ 信息
IronOCR 讀取位於任何護照底部的兩行的 MRZ 信息,這些護照都遵循(國際民用航空組織)ICAO 的標準。 MRZ 數據由兩行數據組成,每一組位置包含獨特的信息。 這裡有一個簡單的表格,顯示信息對應的行索引。
示例輸入
class="content-img-align-center">
class="center-image-wrapper">
第一行
位置
字段
描述
1 文件類型 通常為“P”代表護照
2-3 簽發國 三字母國家代碼(ISO 3166-1 alpha-3)
4-44 姓氏和名字 姓氏後跟“<<”,然後是用“<”分隔的名字
第二行
位置
字段
描述
1-9 護照號碼 唯一的護照號碼
10 校驗位(護照號碼) 護照號碼的校驗位
11-13 國籍 三字母國籍代碼(ISO 3166-1 alpha-3)
14-19 出生日期 出生日期(YYMMDD 格式)
20 校驗位(出生日期) 出生日期的校驗位
21 性別 性別('M' 代表男性,'F' 代表女性,'X' 代表未指定)
22-27 有效期 有效期(YYMMDD 格式)
28 校驗位(有效期) 有效期的校驗位
29-42 個人編號 可選的個人編號(通常為國家身份號碼)
43 校驗位(個人編號) 個人編號的校驗位
44 校驗位(綜合) 總體校驗位
調試
我們還可以通過從護照圖像中獲取原始提取文本和置信度水平來驗證 IronOCR 的結果,以確認提取的信息是否準確。 使用上面的示例,我們可以訪問 OcrPassportResult 對象的 Confidence 和 Text 屬性。
:path=/static-assets/ocr/content-code-examples/how-to/read-passport-debug.cs
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 Confidence level and raw extracted text
Console.WriteLine(result.Confidence);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPassport = New OcrInput()
inputPassport.LoadImage("passport.jpg")
' Perform OCR
Dim result As OcrPassportResult = ocr.ReadPassport(inputPassport)
' Output Confidence level and raw extracted text
Console.WriteLine(result.Confidence)
Console.WriteLine(result.Text)
$vbLabelText
$csharpLabel
Confidence:從 OcrPassportResult 的 Confidence 屬性是一個浮點數,表示 OCR 統計準確性置信度作為每個字符的平均值。 如果護照圖像模糊或含有其它信息,則此浮點數會較低。 一是最高和最有信心的,而 0 是最低和信心最少的。
Text:OcrPassportResult 的 Text 屬性包含從護照圖像中提取的原始未解析文本。 開發人員可以在單元測試中使用此方法來驗證護照圖像的提取文本。
常見問題解答
您可以使用 IronOCR 的ReadPassport方法在 C# 中擷取護照資料。首先,安裝 IronOCR 庫和 IronOcr.Extension.AdvancedScan 套件。匯入護照影像,然後呼叫ReadPassport方法來檢索資料。
IronOCR 可以從護照中提取諸如名字、國家、護照號碼、姓氏、出生日期和到期日期等詳細資訊。
護照資訊識別區(MRZ)位於護照底部兩行,包含關鍵資料。 IronOCR 讀取該區域,並根據國際民航組織(ICAO)標準提取資訊。
您需要安裝 IronOcr.Extension.AdvancedScan 軟體包,並確保您的專案在 x64 架構上運行,才能使用進階掃描功能。
是的,您可以使用OcrPassportResult物件的Confidence屬性來驗證提取資料的準確性,其中接近 1 的值表示置信度高。
目前,IronOCR 支援對英文護照進行資料提取。
提取的資料儲存在OcrPassportResult物件中,每個成員都以字串形式表示,以便於存取和操作。
「文本」屬性可讓您存取和驗證從護照中提取的文本,確保資訊的準確性和完整性。
在使用 IronOCR 之前,請確保護照影像中沒有頁首或頁腳,因為這些內容可能會幹擾資料擷取過程的準確性。
確認已安裝正確的軟體包,確保影像清晰且裁剪正確,並檢查架構相容性(x64)以獲得最佳效能。
技術作家
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。
除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'name'
Filename: sections/author_component.php
Line Number: 70
Backtrace:
File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 70
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view
File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
">
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'title'
Filename: sections/author_component.php
Line Number: 84
Backtrace:
File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 84
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view
File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'comment'
Filename: sections/author_component.php
Line Number: 85
Backtrace:
File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 85
Function: _error_handler
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view
File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view
File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view
File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view
File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once
準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布
nuget.org/packages/IronOcr/
在解決方案資源管理器中,右鍵單擊參考,管理 NuGet 包
選擇瀏覽並搜尋"IronOCR"
選擇包並安裝
下載並解壓縮IronOCR至如~/Libs這樣的目錄
在Visual Studio解決方案資源管理器中,右鍵單擊引用。選擇瀏覽,"IronOCR.dll"
15
1000
1
立即獲取您的免費 30天試用密鑰 。
謝謝。 如果您想與我們的授權團隊交談: