護照 OCR SDK 開發者教學
護照是個人身份的證件。 我們使用護照來旅行並註冊我們生活中的重要方面。 然而,護照的格式並不總是容易閱讀。 想像一下,在假期期間,許多旅行者突然出現以進行旅行和休閒。 移民官員如何能夠通過手動資料輸入處理如此大量的資料並手動檢索正確的資訊?
因此,許多應用程式和企業正在轉向光學字元識別(OCR),這使得開發者能夠快速提取印刷文字和數位圖像。
同樣地,護照OCR是一種技術,它使用光學字元識別(OCR)軟體來從護照中提取有意義的資訊; 它還利用所有護照的機械可讀區來檢索資訊,以快速識別試圖通過移民的個人。 在需要快速識別護照資訊或涉及自動化護照資料提取的過程中,護照OCR是至關重要的,是機場和移民邊境效率和速度的基石。
儘管護照OCR軟體和技術多年來得到了更進一步的發展,但各種因素可能會影響文件掃描過程。 帶有噪聲或污漬的數位圖像可能會嚴重影響護照的準確性。 此外,當在護照上運行時,OCR程式庫有時可能會令人困惑,因為機械可讀區是獨特的結構化資料集。 開發者可能能夠提取資料,但必須自行排序參數。 然而,使用IronOCR,專門的方法已經優化為可以讀取護照; 其結果允許開發者快速獲取和操控資訊,這對於高容量掃描和自動化是理想的。
在本文中,我們將簡要地討論使用IronOCR來獲取和操控護照資訊,以自動化資料提取,並提供關於IronOCR如何與護照互動的進一步資料。
IronOCR:一個C#的OCR程式庫

IronOCR是一個C#的程式庫,提供易於使用的方法和靈活的功能以滿足所有OCR相關的需求。 除了標準技術之外,IronOCR允許開發者充分利用和自訂版本的Tesseract來完成所有相關任務。
以下是一些最著名功能的簡要概述:
- 跨平台相容性:IronOCR與大多數 .NET 平台相容,包括 .NET 8、7、6 和 5,並支持 .NET Framework 4.6.2 以上版本。 使用此程式庫,開發者不用擔心跨平台相容性,因為它還支持所有操作系統,從 Windows、macOS 到 Azure,甚至包括 Linux。
- 靈活性:OCR輸入有多種格式,因此一個程式庫需要處理各種格式才能真正做到靈活。 IronOCR接受所有常見的圖像格式(jpg、png 和 gif),同時支持來自C#的本機 "System.Drawing.Objects",使得更容易整合到現有程式碼庫中。
- 支持和易用性:IronOCR有詳細的文件,配有完整的API和教程,說明所有形式的功能。 此外,有24/5的支持,確保開發者始終得到支持。
- 多語言支持:IronOCR支持多達125種語言,還支持自定義語言,使其對於所有國際文件處理都非常靈活。
使用IronOCR讀取護照
授權金鑰
請記住,IronOCR需要授權金鑰才能運行。 您可以通過存取這個連結獲得免費試用金鑰。
// Replace the license key variable with the trial key you obtained
IronOcr.License.LicenseKey = "REPLACE-WITH-YOUR-KEY";
// Replace the license key variable with the trial key you obtained
IronOcr.License.LicenseKey = "REPLACE-WITH-YOUR-KEY";
' Replace the license key variable with the trial key you obtained
IronOcr.License.LicenseKey = "REPLACE-WITH-YOUR-KEY"
收到試用金鑰後,在您的專案中設置此變數。
程式碼範例
下面的程式碼展示了IronOCR如何採用護照圖像並使用程式庫的護照OCR SDK提取所有相關資訊。
輸入圖像

using IronOcr;
using System;
class Program {
public static void Main() {
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.AddImage("Passport.jpg");
// Perform OCR to read the passport
OcrResult result = ocr.Read(inputPassport);
// Output passport information
Console.WriteLine("Given Names: " + result.Passport?.GivenNames);
Console.WriteLine("Country: " + result.Passport?.Country);
Console.WriteLine("Passport Number: " + result.Passport?.PassportNumber);
Console.WriteLine("Surname: " + result.Passport?.Surname);
Console.WriteLine("Date of Birth: " + result.Passport?.DateOfBirth.ToString("yyyy-MM-dd"));
Console.WriteLine("Date of Expiry: " + result.Passport?.DateOfExpiry.ToString("yyyy-MM-dd"));
}
}
using IronOcr;
using System;
class Program {
public static void Main() {
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.AddImage("Passport.jpg");
// Perform OCR to read the passport
OcrResult result = ocr.Read(inputPassport);
// Output passport information
Console.WriteLine("Given Names: " + result.Passport?.GivenNames);
Console.WriteLine("Country: " + result.Passport?.Country);
Console.WriteLine("Passport Number: " + result.Passport?.PassportNumber);
Console.WriteLine("Surname: " + result.Passport?.Surname);
Console.WriteLine("Date of Birth: " + result.Passport?.DateOfBirth.ToString("yyyy-MM-dd"));
Console.WriteLine("Date of Expiry: " + result.Passport?.DateOfExpiry.ToString("yyyy-MM-dd"));
}
}
Imports IronOcr
Imports System
Friend Class Program
Public Shared Sub Main()
' Instantiate OCR engine
Dim ocr = New IronTesseract()
Dim inputPassport = New OcrInput()
inputPassport.AddImage("Passport.jpg")
' Perform OCR to read the passport
Dim result As OcrResult = ocr.Read(inputPassport)
' Output passport information
Console.WriteLine("Given Names: " & result.Passport?.GivenNames)
Console.WriteLine("Country: " & result.Passport?.Country)
Console.WriteLine("Passport Number: " & result.Passport?.PassportNumber)
Console.WriteLine("Surname: " & result.Passport?.Surname)
Console.WriteLine("Date of Birth: " & result.Passport?.DateOfBirth.ToString("yyyy-MM-dd"))
Console.WriteLine("Date of Expiry: " & result.Passport?.DateOfExpiry.ToString("yyyy-MM-dd"))
End Sub
End Class
程式碼說明
- 導入程式庫:我們首先將IronOCR和其他必要的程式庫導入程式碼基。
- 實例化OCR引擎:我們建立一個新的
IronTesseract物件以初始化OCR引擎。 - 載入護照圖像:然後我們建立一個新的
AddImage()載入包含護照的圖像。 - 使用OCR讀取護照:我們使用
Read()方法在輸入圖像上執行OCR操作並保存結果。 - 輸出結果:我們輸出提取的護照資訊,如名字、國家、護照號碼、姓氏、出生日期和到期日期。
控制台輸出

機械可讀區
IronOCR可以從任意護照的底部兩行提取依據國際民航組織(ICAO)標準的機械可讀區(MRZ)資訊。 MRZ資料包括兩行,每行包含獨特的資訊。
這是一個簡要的表格展示:

護照OCR的挑戰及除錯
圖像質量在掃描數位圖像時始終是一個問題。 變形的圖像質量會遮蔽資訊,並使得確認資料的準確性變得更加困難。 此外,開發者在處理關鍵任務資訊(例如護照)時,必須考慮資料安全和合規性。
IronOCR還提供了一種除錯方法,並展示了互動資訊的概念。 這些方法允許開發者進行故障排除,並對提取的資料充滿信心。
這是一個簡單的範例:
using IronOcr;
using System;
class DebugExample {
public static void Main() {
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.AddImage("Passport.jpg");
// Perform OCR
OcrResult result = ocr.Read(inputPassport);
// Output Confidence level and raw extracted text
Console.WriteLine("OCR Confidence: " + result.Confidence);
Console.WriteLine("Extracted Text: ");
Console.WriteLine(result.Text);
}
}
using IronOcr;
using System;
class DebugExample {
public static void Main() {
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.AddImage("Passport.jpg");
// Perform OCR
OcrResult result = ocr.Read(inputPassport);
// Output Confidence level and raw extracted text
Console.WriteLine("OCR Confidence: " + result.Confidence);
Console.WriteLine("Extracted Text: ");
Console.WriteLine(result.Text);
}
}
Imports IronOcr
Imports System
Friend Class DebugExample
Public Shared Sub Main()
' Instantiate OCR engine
Dim ocr = New IronTesseract()
Dim inputPassport = New OcrInput()
inputPassport.AddImage("Passport.jpg")
' Perform OCR
Dim result As OcrResult = ocr.Read(inputPassport)
' Output Confidence level and raw extracted text
Console.WriteLine("OCR Confidence: " & result.Confidence)
Console.WriteLine("Extracted Text: ")
Console.WriteLine(result.Text)
End Sub
End Class
除錯程式碼說明
- 置信度:
OcrResult中是一個浮點數,代表OCR的統計準確性置信度,其計算是基於每個字元的平均值。 較低的值表明護照圖像可能模糊或包含多餘資訊。 1表示最高置信度,0表示最低置信度。 - 文字:
OcrResult中保存了從護照圖像中提取的未處理文字。 開發者可以在單元測試中使用它來驗證從護照圖像中提取的文字是否通過相等斷言。
結論

護照OCR技術通過自動化資料提取並提高運營效率顯著提升了文件處理。 它簡化了身份驗證和KYC過程,在處理敏感的個人資訊時確保高精度。 選擇IronOCR作為他們的護照OCR API,移民邊境和機場可以減少處理時間並提高工作效率。
IronOCR通過其易用的方法為開發者提供了靈活性和可擴展性。 它允許開發者通過OcrResult物件快速排序資訊。 此外,IronOCR提供除錯工具,包括置信水平和未解析的原始文字,供開發者在產品單元測試中使用。 IronOCR還透過清除護照圖像輸入以進行方法操作,手動最小化數位噪音以便更高級的使用。
可以利用IronOCR的免費試用授權頁面。
常見問題
如何使用OCR在C#中提取護照資訊?
您可以使用IronOCR來處理護照圖像,利用其強大的OCR功能從機讀區域中提取資料。
使用OCR進行護照資料處理的好處是什麼?
使用OCR進行護照資料處理可自動提取資訊,顯著提高如機場和邊境管制等高流量區域的效率和準確性。
使用OCR技術能夠處理多種語言嗎?
是的,IronOCR支持最多125種語言,並允許新增自定義語言,使其在處理國際文件時具有多樣性。
IronOCR如何確保從護照中準確提取資料?
IronOCR在OcrResult中提供了一個'Confidence'屬性來表示統計準確性,使開發者能夠驗證提取資料的可靠性。
IronOCR支持哪些圖像格式來掃描護照?
IronOCR支持所有流行的圖像格式,包括jpg、png和gif,還可以與C#原生的System.Drawing.Objects一起使用以便於整合。
開發者在實施護照OCR時可能面臨哪些挑戰?
挑戰包括處理低質量圖像、確保資料安全、遵循處理敏感護照資訊的合規。
開發者如何開始使用IronOCR進行護照OCR?
開發者可以從提供商網站獲取試用授權金鑰,並按照詳細的文件將其整合到他們的C#應用中。
IronOCR與哪些平台相容?
IronOCR相容大多數.NET平台,包括.NET 8、7、6、5,以及.NET Framework 4.6.2及以上,且支持主要的作業系統如Windows、macOS、Azure和Linux。



