IronOCR 操作指南 進階閱讀的 OCR 設定 進階閱讀的 OCR 配置 Curtis Chau 更新:2026年2月26日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronOCR provides advanced scan reading methods such as ReadPassport, ReadLicensePlate, and ReadPhoto that go beyond standard OCR. 這些方法由IronOCR套件提供支援。 To fine-tune how these methods process text, IronOCR exposes the TesseractConfiguration class, giving developers full control over character whitelisting, blacklisting, barcode detection, data table reading, and more. This article covers the TesseractConfiguration properties available for advanced reading and practical examples for configuring OCR in real-world scenarios. 快速入門:將 OCR 輸出限制為字元白名單 Set WhiteListCharacters on TesseractConfiguration before calling Read. 任何不在白名單中的字元都會被靜默地從結果中刪除,從而消除雜訊而無需任何後製處理。 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronOcr PM > Install-Package IronOcr 複製並運行這段程式碼。 var result = new IronTesseract() { Configuration = new TesseractConfiguration { WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- " } }.Read(new OcrInput("image.png")); Console.WriteLine(result.Text); 部署到您的生產環境進行測試 今天就在您的專案中開始使用免費試用IronOCR Free 30 Day Trial 如何配置 OCR 以實現進階閱讀 從NuGet安裝IronOCR 安裝IronOCR包 配置TesseractConfiguration屬性,例如WhiteListCharacters和ReadBarCodes 使用OcrInput載入輸入影像 使用ReadPhoto 、 ReadLicensePlate或ReadPassport等高階方法讀取影像。 Tesseract配置屬性 The TesseractConfiguration class provides the following properties for customizing OCR behavior. These are set through IronTesseract.Configuration. 屬性 類型 描述 WhiteListCharacters 細繩 OCR 輸出僅識別此字串中存在的字符,所有其他字符都將被排除。 BlackListCharacters 細繩 該字串中的字元將被主動忽略並從 OCR 輸出中刪除。 ReadBarCodes 布林值 在 OCR 處理過程中啟用或停用文件中的條碼偵測。 ReadDataTables 布林值 使用 Tesseract 啟用或停用文件中的表格結構偵測。 PageSegmentationMode TesseractPageSegmentationMode 決定 Tesseract 如何分割輸入影像。選項包括AutoOsd 、 Auto 、 SingleBlock 、 SingleLine 、 SingleWord等。 RenderSearchablePdf 布林值 啟用後,OCR 輸出可以儲存為具有不可見文字圖層的可搜尋 PDF。 RenderHocr 布林值 啟用後,OCR 輸出將包含 hOCR 數據,以便進一步處理或匯出。 TesseractVariables Dictionary<細繩, object> Provides direct access to low-level Tesseract configuration variables for fine-grained control. The TesseractVariables dictionary goes further still, exposing hundreds of underlying Tesseract engine parameters for cases where the high-level properties are not sufficient. 以下範例示範了每個屬性組,首先是字元白名單。 設定車牌字元白名單 A common use case for WhiteListCharacters is restricting OCR output to only the characters that can appear on a license plate: uppercase letters, digits, hyphens, and spaces. 這樣可以消除噪聲,提高準確性,方法是告訴引擎忽略預期字元集以外的所有內容。 輸入 The following vehicle registration record contains a mix of uppercase text, lowercase text, special symbols (@, $, #, |, ~, ^, *), and punctuation. BlackListCharacters supplements the whitelist by actively excluding known noise symbols like `, ~, @, #, $, %, &, and *. :path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading.cs using IronOcr; // Initialize the Tesseract OCR engine IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { // Whitelist only characters that appear on license plates WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ", // Blacklist common noise characters BlackListCharacters = "`~@#$%&*", }; var ocrInput = new OcrInput(); // Load the input image ocrInput.LoadImage("advanced-input.png"); // Perform OCR on the input image with ReadPhoto method var results = ocr.ReadPhoto(ocrInput); // Print the filtered text result to the console Console.WriteLine(results.Text); Imports IronOcr ' Initialize the Tesseract OCR engine Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { ' Whitelist only characters that appear on license plates .WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ", ' Blacklist common noise characters .BlackListCharacters = "`~@#$%&*" } Dim ocrInput As New OcrInput() ' Load the input image ocrInput.LoadImage("advanced-input.png") ' Perform OCR on the input image with ReadPhoto method Dim results = ocr.ReadPhoto(ocrInput) ' Print the filtered text result to the console Console.WriteLine(results.Text) $vbLabelText $csharpLabel 輸出 白名單濾波的效果在結果中清晰可見: "車牌:ABC-1234"變成"P ABC-1234" 。 小寫字母"late:"省略,而車牌號碼則完全保留。 "VIN: 1HGBH41JXMN109186"變為"VIN 1HGBH41JXMN109186" 。 冒號被省略,但大寫的車輛識別碼和完整號碼被保留。 "Owner: john.doe@email.com"變成"O" 。 所有小寫電子郵件地址和標點符號均被刪除。 -地區:CA-90210 | "5區"變為"R CA-90210 Z 5" 。 管道(|) and hash (#) are removed, while the uppercase letters and numbers survive. *"費用:$125.00 + 稅"變為"F 12500"** 。 美元符號、小數點、Plus號和小寫字母"tax"都被移除。 "Ref: ~record_v2^final"變成"R 2" 。 The tilde (~), underscore, caret (^), and all lowercase characters are stripped. The same WhiteListCharacters and BlackListCharacters approach works for any document type, not just license plates. 下一節將展示如何擴展讀取操作,以便在同一次讀取過程中偵測條碼和表格結構。 條碼和資料表讀取配置 IronOCR可以偵測文件中的條碼、結構化表格以及文字。 These features are controlled through TesseractConfiguration: IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { // Enable barcode detection within documents ReadBarCodes = true, // Enable table structure detection ReadDataTables = true, }; IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { // Enable barcode detection within documents ReadBarCodes = true, // Enable table structure detection ReadDataTables = true, }; Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .ReadBarCodes = True, .ReadDataTables = True } $vbLabelText $csharpLabel ReadBarCodes: When set to true, IronOCR scans the document for barcodes in addition to text. Set to false to skip barcode detection and speed up processing when barcodes are not expected. ReadDataTables: When set to true, Tesseract attempts to detect and preserve table structures in the document. 這對於發票、報告和其他表格文件非常有用。 These options can be combined with WhiteListCharacters and BlackListCharacters for precise control over what is extracted from complex documents. 過濾和檢測控制著提取的內容,而佈局解釋則是另一個需要考慮的問題。 The next section covers how to select the right PageSegmentationMode for the document type. 控制頁面分段模式 PageSegmentationMode tells Tesseract how to segment the input image before recognition. 為給定佈局選擇錯誤的模式會導致引擎誤讀或完全跳過文字。 模式 使用案例 AutoOsd 自動版面分析,具備方向與腳本偵測功能 Auto 自動佈局分析(不含 OSD)(預設) SingleColumn 假設圖像為單列文字。 SingleBlock 假設影像是由單一均勻的文字區塊組成。 SingleLine 假設圖像是一行文字。 SparseText 盡可能多地查找文本,順序不限。 For a label or banner that contains a single line, SingleLine eliminates multi-block analysis and improves both speed and accuracy. 輸入 single-line-label.png is a narrow shipping label with exactly one line of bold Courier text: SHIPPING LABEL: TRK-2024-XR9-001. IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { PageSegmentationMode = TesseractPageSegmentationMode.SingleLine, }; using OcrInput input = new OcrInput(); input.LoadImage("single-line-label.png"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { PageSegmentationMode = TesseractPageSegmentationMode.SingleLine, }; using OcrInput input = new OcrInput(); input.LoadImage("single-line-label.png"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); Imports IronOcr Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .PageSegmentationMode = TesseractPageSegmentationMode.SingleLine } Using input As New OcrInput() input.LoadImage("single-line-label.png") Dim result As OcrResult = ocr.Read(input) Console.WriteLine(result.Text) End Using $vbLabelText $csharpLabel For a scanned page with irregular text placement, SparseText recovers more content than Auto. 輸入 receipt-scan.png is a Corner Market thermal receipt with four line items (coffee, muffin, juice, granola bar), a dashed separator, subtotal, tax, and total. 在這種佈局中,固定區塊分割會遺漏不同水平位置的條目。 IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { PageSegmentationMode = TesseractPageSegmentationMode.SparseText, }; using OcrInput input = new OcrInput(); input.LoadImage("receipt-scan.png"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { PageSegmentationMode = TesseractPageSegmentationMode.SparseText, }; using OcrInput input = new OcrInput(); input.LoadImage("receipt-scan.png"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); Imports IronTesseract Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .PageSegmentationMode = TesseractPageSegmentationMode.SparseText } Using input As New OcrInput() input.LoadImage("receipt-scan.png") Dim result As OcrResult = ocr.Read(input) Console.WriteLine(result.Text) End Using $vbLabelText $csharpLabel 佈局分割已根據文件類型進行了調整,下一步是控制下游處理的輸出格式。 產生可搜尋的 PDF 和 hOCR 輸出 RenderSearchablePdf and RenderHocr control the output formats that IronOCR produces alongside the plain text result. RenderSearchablePdf embeds an invisible text layer over the original image, producing a PDF where users can search and copy text while the scanned image remains visible. 這是文件歸檔工作流程的標準輸出格式。 輸入 scanned-document.pdf is a single-page business letter from IronOCR Solutions Ltd. (dated 15 March 2024, reference DOC-2024-OCR-0315). The result is saved as searchable-output.pdf. IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { RenderSearchablePdf = true, }; using OcrInput input = new OcrInput(); input.LoadPdf("scanned-document.pdf"); OcrResult result = ocr.Read(input); result.SaveAsSearchablePdf("searchable-output.pdf"); IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { RenderSearchablePdf = true, }; using OcrInput input = new OcrInput(); input.LoadPdf("scanned-document.pdf"); OcrResult result = ocr.Read(input); result.SaveAsSearchablePdf("searchable-output.pdf"); Imports IronOcr Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .RenderSearchablePdf = True } Using input As New OcrInput() input.LoadPdf("scanned-document.pdf") Dim result As OcrResult = ocr.Read(input) result.SaveAsSearchablePdf("searchable-output.pdf") End Using $vbLabelText $csharpLabel 輸出 輸出結果是一個 PDF 文件,它看起來與輸入文件完全相同,但其中包含一個隱藏的文字層。 Open searchable-output.pdf and use Ctrl+F to verify that the embedded text is searchable and copyable. RenderHocr produces an hOCR document, an HTML file that encodes the text content together with bounding box coordinates for every word. 當下游工具需要精確的字詞定位時,例如編輯引擎或文件佈局分析,這非常有用。 輸入 document-page.png is a document page with the heading "Quarterly Summary Q1 2024" and two paragraphs of financial data covering revenue, operating costs, and growth drivers. The result is saved as output.html. IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { RenderHocr = true, }; using OcrInput input = new OcrInput(); input.LoadImage("document-page.png"); OcrResult result = ocr.Read(input); result.SaveAsHocrFile("output.html"); IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { RenderHocr = true, }; using OcrInput input = new OcrInput(); input.LoadImage("document-page.png"); OcrResult result = ocr.Read(input); result.SaveAsHocrFile("output.html"); Imports IronOcr Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .RenderHocr = True } Using input As New OcrInput() input.LoadImage("document-page.png") Dim result As OcrResult = ocr.Read(input) result.SaveAsHocrFile("output.html") End Using $vbLabelText $csharpLabel 輸出 output.html encodes each recognized word with its bounding box coordinates. 在瀏覽器中開啟檔案以檢查 hOCR 結構,或將其傳遞給下游工具進行佈局分析或編輯。 如果您需要從單一讀取呼叫中獲得所有三種輸出格式(純文字、可搜尋 PDF 和 hOCR),則可以同時啟用這兩個標誌。 這些輸出標誌與讀取的語言無關,包括非拉丁字母。下一節將介紹如何對日文文字套用字元過濾。 國際文檔的Unicode字元過濾 For international documents in Chinese, Japanese, or Korean, the WhiteListCharacters and BlackListCharacters properties work with Unicode characters. 這樣可以將輸出限制為特定腳本,例如日文僅輸出平假名和片假名。 請注意 請確保已安裝對應的語言包(例如IronOCR ),然後再繼續。 輸入 這份文件包含標題 (テsuto)、混合平假名和片假名以及濁音變體 (プ、で) 的日文句子、包含列入黑名單的噪音符號 (★、■) 和漢字 (価格) 的價格線、包含另一個列入黑名單的符號 (§) 的備註行、価格) 的價格線、包含另一個列入黑名單的符號 (§) 的備註行、更多漢斯(プ和基本片假名(メモ,ール)。 白名單僅允許平假名、片假名、數字和常用日文標點符號通過; 這三個噪音符號已被明確列入黑名單。 The Unicode character ranges for Hiragana and Katakana are passed as 細繩 literals in WhiteListCharacters, with the noise symbols listed in BlackListCharacters. 警告 控制台可能不支援顯示 Unicode 字元。 將輸出重定向到 .txt 檔案是處理此類字元時驗證結果的可靠方法。 :path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-jp.cs using IronOcr; using System.IO; IronTesseract ocr = new IronTesseract(); ocr.Configuration = new TesseractConfiguration { // Whitelist only Hiragana, Katakana, numbers, and common Japanese punctuation WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" + "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" + "0123456789、。?!()¥ー", // Blacklist common noise/symbols you want to ignore BlackListCharacters = "★■§", }; var ocrInput = new OcrInput(); // Load Japanese input image ocrInput.LoadImage("jp.png"); // Perform OCR on the input image with ReadPhoto method var results = ocr.ReadPhoto(ocrInput); // Write the text result directly to a file named "output.txt" File.WriteAllText("output.txt", results.Text); // You can add this line to confirm the file was saved: Console.WriteLine("OCR results saved to output.txt"); Imports IronOcr Imports System.IO Dim ocr As New IronTesseract() ocr.Configuration = New TesseractConfiguration With { .WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" & "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" & "0123456789、。?!()¥ー", .BlackListCharacters = "★■§" } Dim ocrInput As New OcrInput() ' Load Japanese input image ocrInput.LoadImage("jp.png") ' Perform OCR on the input image with ReadPhoto method Dim results = ocr.ReadPhoto(ocrInput) ' Write the text result directly to a file named "output.txt" File.WriteAllText("output.txt", results.Text) ' You can add this line to confirm the file was saved: Console.WriteLine("OCR results saved to output.txt") $vbLabelText $csharpLabel 輸出 完整的過濾輸出以文字檔案的形式提供: jp-output.txt 。 因為白名單只包含基本的平假名和片假名字符,所以像プ(pu)和デ(de)這樣的派生聲標變體被刪除了。 像価格(價格)和購入(購買)這樣的漢字也被排除在外,因為它們不在白名單字符集中。 Blacklisted symbols like ★, ■, and § are actively removed regardless of the whitelist. 接下來我該去哪裡? 現在您已經了解如何設定IronOCR以適應進階閱讀場景,請探索以下內容: 讀取特定類型的文件,例如護照和車牌 -條碼和二維碼讀取作為獨立的 OCR 用例 從處理結果匯出 hOCR 和可搜尋的 PDF 文件 對於生產使用,請記得取得授權以移除水印並存取完整功能。 常見問題解答 IronOCR 中的 TesseractConfiguration 是什麼? IronOCR 中的 TesseractConfiguration 允許使用者自訂 OCR 設定,從而啟用進階讀取功能,例如字元白名單、BarCode 讀取及多語言支援。 如何在 IronOCR 中設定字元白名單? 在 IronOCR 中,您可以透過 TesseractConfiguration 設定字元白名單,藉此指定 OCR 引擎應識別的字元,此功能對於讀取車牌號碼等任務非常實用。 IronOCR 能否讀取 BarCode 和資料表? 是的,IronOCR 可透過調整 TesseractConfiguration 屬性中的特定設定,來讀取 BarCode 和資料表,以實現精確的 OCR 資料擷取。 IronOCR 是否支援中文、日文和韓文等國際語言? IronOCR 透過其多語言 TesseractConfiguration 選項,支援包括中文、日文及韓文在內的國際語言。 在 IronOCR 中使用進階 OCR 設定有哪些好處? 透過 IronOCR 的進階 OCR 設定,可實現更精準且高效的文字辨識,並支援語言特定文字辨識及結構化資料擷取等專業任務。 是否可以針對特定的 OCR 任務來優化 IronOCR? 是的,IronOCR 可透過設定字元白名單、啟用 BarCode 或表格辨識等功能,針對特定 OCR 任務進行優化,從而提升特定應用程式的效能。 如何在 IronOCR 中啟用多語言支援? 若要在 IronOCR 中啟用多語言支援,您可以調整 TesseractConfiguration 中的語言設定,讓 OCR 引擎能夠識別多種語言的文字。 何謂字元白名單,以及它們在 IronOCR 中如何使用? IronOCR 中的字元白名單是 OCR 引擎設定為可識別的特定字元清單,非常適合用於讀取數字或特定文字模式等專注型任務。 IronOCR 能否用於讀取結構化資料格式? 是的,IronOCR 可設定為讀取並處理結構化資料格式(例如 BARCODE 和表格),為各種資料擷取需求提供多功能的 OCR 功能。 IronOCR 提供哪些進階文字辨識設定選項? IronOCR 提供字元白名單、多語言支援及 BarCode 辨識等設定選項,以強化進階文字辨識能力,並能針對特定需求進行客製化調整。 Curtis Chau 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 5,570,591 | 版本: 2026.4 剛剛發布 開始免費試用 免費 NuGet 下載 總下載量:5,570,591 查看許可證 還在捲動嗎? 想要快速證明? PM > Install-Package IronOcr 執行範例 觀看您的圖片變成可搜尋的文字。 免費 NuGet 下載 總下載量:5,570,591 查看許可證