IronOCR 教學 專業文件 如何使用 C# 和 IronOCR 讀取專業文檔 Curtis Chau 更新:10月 12, 2025 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English 用單一的通用方法準確解讀標準文本文件、車牌、護照和照片等特定文件是非常困難的。 這些挑戰源自於每種文件類型的格式、佈局和內容的多樣性,以及影像品質、失真和專業內容的差異。 此外,隨著文件類型範圍的擴大,實現上下文理解以及平衡效能和效率變得更加複雜。 IronOCR 引入了針對特定文件(例如標準文字檔案、車牌、護照和照片)執行 OCR 的具體方法,以實現最佳的準確性和性能。 快速入門:一行讀懂護照 使用 IronOCR 的ReadPassport擴充程序,只需極少的設定即可提取所有關鍵護照資訊。只需一行程式碼(假設您已安裝 IronOCR 和 AdvancedScan),即可快速輕鬆地獲得結構化的結果數據,例如姓名、護照號碼、國家/地區等。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronOCR PM > Install-Package IronOcr 複製並運行這段程式碼。 var result = new IronTesseract().ReadPassport(new OcrInput().LoadImage("passport.jpg")); 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronOCR,免費試用! 免費試用30天 最小工作流程(5 個步驟) 下載一個用於讀取車牌、護照和照片的 C# 庫。 準備圖像和 PDF 文件以進行 OCR 設定ReadLicensePlate方法以讀取車牌 設定ReadPassport方法以從護照中檢索資訊。 利用ReadPhoto和ReadScreenShot方法讀取包含難以辨識文字的圖像 關於包裹 ReadLicensePlate 、 ReadPassport 、 ReadPhoto和ReadScreenShot方法都是 IronOCR 基本套件的擴充方法,需要安裝IronOcr.Extensions.AdvancedScan套件。 這些方法可與 OCR 引擎配置(例如黑名單和白名單)搭配使用。除ReadPassport方法外,所有方法均支援多種語言,包括中文、日語、韓語和拉丁字母。 請注意,每種語言都需要額外的語言包IronOcr.Languages 。 在 .NET Framework 上使用進階掃描功能需要專案在 x64 架構上運作。 進入專案配置,取消選取"首選 32 位元"選項即可實現此目的。 請參閱以下故障排除指南以了解更多資訊:". NET Framework 進階掃描"。 閱讀文件範例 ReadDocument方法是一種強大的文件讀取方法,專門用於讀取包含大量文字的掃描文件或紙本文件的照片。 PageSegmentationMode配置對於讀取不同佈局的文字檔案非常重要。 例如, SingleBlock和SparseText類型可以從表格佈局中檢索大量資訊。 這是因為SingleBlock假定文字保持為一個區塊,而SparseText假定文字分散在整個文件中。 :path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-document.cs 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); Imports IronOcr Imports System ' Instantiate OCR engine Private ocr = New IronTesseract() ' Configure OCR engine ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock Dim input = New OcrInput() input.LoadPdf("Five.pdf") ' Perform OCR Dim result As OcrResult = ocr.ReadDocument(input) Console.WriteLine(result.Text) $vbLabelText $csharpLabel 以下方法是基本 IronOCR 套件的擴充方法,需要安裝IronOcr.Extensions.AdvancedScan套件。 讀取車牌範例 ReadLicensePlate方法針對從照片中讀取車牌進行了最佳化。 此方法傳回的特殊資訊是Licenseplate屬性,其中包含所提供文件中車牌位置的資訊。 :path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-license-plate.cs 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; Imports IronOcr Imports IronSoftware.Drawing Imports System ' Instantiate OCR engine Private ocr = New IronTesseract() Private inputLicensePlate = New OcrInput() inputLicensePlate.LoadImage("LicensePlate.jpeg") ' Perform OCR Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate) ' Retrieve license plate coordinates Dim rectangle As Rectangle = result.Licenseplate ' Retrieve license plate value Dim output As String = result.Text $vbLabelText $csharpLabel 閱讀護照範例 ReadPassport方法經過最佳化,可透過掃描機讀區 (MRZ) 內容,從護照照片中讀取和提取護照資訊。 MRZ 是護照、身分證和簽證等官方文件中特別定義的區域。 MRZ 通常包含重要的個人信息,例如持有人的姓名、出生日期、國籍和證件號碼。 目前,此方法僅支援英語。 :path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-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 結果 請確保文件中僅包含護照照片。 任何頁首和頁尾文字都可能幹擾該方法,並導致意外的輸出。 查看照片範例 ReadPhoto方法針對讀取包含難以辨識文字的影像進行了最佳化。 此方法傳回TextRegions屬性,其中包含有關檢測到的文字的有用信息,例如Region 、 TextInRegion和FrameNumber 。 :path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-photo.cs 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; Imports IronOcr Imports IronSoftware.Drawing ' Instantiate OCR engine Private ocr = New IronTesseract() Private inputPhoto = New OcrInput() inputPhoto.LoadImageFrame("photo.tif", 2) ' Perform OCR Dim result As OcrPhotoResult = ocr.ReadPhoto(inputPhoto) ' index number refer to region order in the page Dim number As Integer = result.TextRegions(0).PageNumber Dim textinregion As String = result.TextRegions(0).TextInRegion Dim region As Rectangle = result.TextRegions(0).Region $vbLabelText $csharpLabel 閱讀螢幕截圖範例 ReadScreenShot方法針對讀取包含難以閱讀的文字的螢幕截圖進行了最佳化。 與 ReadPhoto 方法類似,它也傳回TextRegions屬性。 :path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-screenshot.cs } 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); } Imports IronOcr Imports System Imports System.Linq ' Instantiate OCR engine Private ocr = New IronTesseract() Private inputScreenshot = New OcrInput() inputScreenshot.LoadImage("screenshot.png") ' Perform OCR Dim result As OcrPhotoResult = 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) } $vbLabelText $csharpLabel 常見問題解答 如何在 C# 中使用 OCR 讀取車牌? 您可以使用 IronOCR 提供的 ReadLicensePlate 方法從照片中準確讀取車牌。此方法會返回車牌文字及其位置的詳細資訊。 從護照照片中提取資訊的最佳方法是什麼? IronOCR 的 ReadPassport 方法旨在掃描護照照片中的機器可讀區域 (MRZ),提取姓名、出生日期和證件號碼等基本資訊。 IronOCR 可以讀取照片中難懂的文字嗎? 是的,IronOCR 中的 ReadPhoto 方法經過優化,可以讀取帶有難以讀取的文字的圖像,提供有關檢測到的文字及其區域的詳細資料。 是否可以使用 IronOCR 閱讀截圖中的文字? 絕對的,IronOCR 的 ReadScreenShot 方法特別針對處理螢幕截圖中的文字進行了最佳化,並提供詳細的文字區域資訊。 如何提高布局複雜的文件的 OCR 準確度? 若要增強複雜文件佈局的 OCR 精確度,請在 IronOCR 中設定 PageSegmentationMode 。SingleBlock 和 SparseText 等選項對於從表格版面擷取資訊特別有用。 如果 IronOCR 的進階掃描功能無法在我的 .NET Framework 專案上運作,該怎麼辦? 在專案設定中取消勾選「Prefer 32-bit」選項,以確保您的專案設定在 x64 架構上執行,以解決 IronOCR for .NET Framework 的進階掃描功能問題。 IronOCR 是否有語言支援限制? IronOCR 支援多種語言,包括中文、日文、韓文和 LatinAlphabet。但是,ReadPassport 方法目前僅支援英文文件。 使用 IronOCR 中的進階掃描功能需要哪些條件? 若要使用 IronOCR 中的進階掃描功能,需要 IronOcr.Extensions.AdvancedScan 套件,此套件僅在 Windows 上提供。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 5,167,857 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:5,167,857 檢視授權