IronOCR 操作指南 數據輸出 如何使用 IronOCR 在 C# 中萃取讀取結果。 Curtis Chau 更新:2026年1月10日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 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 的 Read 方法會返回一個 OcrResult 物件,其中包含擷取的文字以及詳細的元資料,包括每個偵測到的元素的精確座標、尺寸、文字方向以及層級結構 (段落、行、字、符號)。 OCR 結果包含偵測到的段落、行、字詞和個別字元的全面資訊。 對於每個元素,它會提供文字內容、精確的 X 與 Y 座標、尺寸(寬度與高度)、文字方向(從左至右或從上至下),以及在 CropRectangle 物件中的位置。 快速入門:從檢測到的第一個單字中檢索單字文字 使用 IronTesseract 的 Read 方法對影像進行 OCR,並使用 Words 集合擷取第一個字的文字。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronOCR PM > Install-Package IronOcr 複製並運行這段程式碼。 string wordText = new IronTesseract().Read("file.jpg").Words[0].Text; 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronOCR,免費試用! 免費試用30天 ### 最小工作流程(5 個步驟) 下載用於存取讀取結果的 C# 庫 準備目標圖像和PDF文檔 使用Read方法對匯入的文件執行 OCR 操作。 訪問結果的X、Y、寬度、高度和文本方向 檢查檢測到的段落、行、單詞和字符比較 我可以從 OCR 結果中擷取哪些資料? 結果值不僅包含擷取的文字,還包含 IronOCR 在 PDF 和影像文件中發現的頁面、段落、行、字、符號和條碼等資訊。 您可以使用 Read 方法從傳回的 OcrResult 物件存取這些資訊。 IronOCR 的綜合結果系統建基於功能強大的 Tesseract 5 引擎,為開發人員提供超越簡單文字辨識的結構化資料擷取功能。 無論是處理 掃描的文件、照片,或是 螢幕截圖,OcrResult 類別都能讓您對擷取的資料進行細部控制。 :path=/static-assets/ocr/content-code-examples/how-to/read-results-output-information.cs using IronOcr; using System; using static IronOcr.OcrResult; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add image using var imageInput = new OcrImageInput("sample.jpg"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Retrieve list of detected paragraphs Paragraph[] paragraphs = ocrResult.Paragraphs; // Output information to console Console.WriteLine($"Text: {paragraphs[0].Text}"); Console.WriteLine($"X: {paragraphs[0].X}"); Console.WriteLine($"Y: {paragraphs[0].Y}"); Console.WriteLine($"Width: {paragraphs[0].Width}"); Console.WriteLine($"Height: {paragraphs[0].Height}"); Console.WriteLine($"Text direction: {paragraphs[0].TextDirection}"); Imports IronOcr Imports System Imports IronOcr.OcrResult ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Add image Private imageInput = New OcrImageInput("sample.jpg") ' Perform OCR Private ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Retrieve list of detected paragraphs Private paragraphs() As Paragraph = ocrResult.Paragraphs ' Output information to console Console.WriteLine($"Text: {paragraphs(0).Text}") Console.WriteLine($"X: {paragraphs(0).X}") Console.WriteLine($"Y: {paragraphs(0).Y}") Console.WriteLine($"Width: {paragraphs(0).Width}") Console.WriteLine($"Height: {paragraphs(0).Height}") Console.WriteLine($"Text direction: {paragraphs(0).TextDirection}") $vbLabelText $csharpLabel 如何從 OCR 結果存取文字內容? OcrResult 物件以簡單、直覺的方式呈現擷取的文字,讓開發人員可以直接使用或將其整合到其他應用程式元件中。 階層式結構反映自然的文件文字組織,可直接處理不同粒度層級的內容。 對於需要 多語言支援的應用程式,IronOCR 可無縫處理多語言文件,在所有 125 種支援語言中保持相同的結構化結果格式。 以下的程式碼範例在一個循環中列印文字以驗證結果。 :path=/static-assets/ocr/content-code-examples/how-to/read-results-output-text.cs using IronOcr; using System; using static IronOcr.OcrResult; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add image using var imageInput = new OcrImageInput("sampleText.png"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Retrieve list of detected paragraphs Paragraph[] paragraphs = ocrResult.Paragraphs; // Loop through each paragraph in the array Console.WriteLine("--- All Detected Paragraphs ---"); foreach (Paragraph paragraph in paragraphs) { // Print the text of the current paragraph Console.WriteLine(paragraph.Text); // Add a blank line for better separation (optional) Console.WriteLine(); } Imports IronOcr Imports System Imports IronOcr.OcrResult ' Instantiate IronTesseract Dim ocrTesseract As New IronTesseract() ' Add image Using imageInput As New OcrImageInput("sampleText.png") ' Perform OCR Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Retrieve list of detected paragraphs Dim paragraphs As Paragraph() = ocrResult.Paragraphs ' Loop through each paragraph in the array Console.WriteLine("--- All Detected Paragraphs ---") For Each paragraph As Paragraph In paragraphs ' Print the text of the current paragraph Console.WriteLine(paragraph.Text) ' Add a blank line for better separation (optional) Console.WriteLine() Next End Using $vbLabelText $csharpLabel 輸出 控制台輸出顯示 IronOCR 正逐行精確地抽取段落文字。 該引擎可自動偵測段落邊界,非常適合處理包含多個文字區塊的複雜文件。 如何取得偵測到的文字的位置座標? 除了擷取的文字之外,OcrResult 還提供詳細的位置資料。 此空間資訊對於需要維持版面忠實度或從特定文件區域執行目標文字擷取的應用程式至關重要。 坐標系統使用從頁面左上角開始的標準像素量測。 若要增強基於座標的作業精確度,請考慮使用 OCR 區域定位來專注於特定區域,或利用 Computer Vision 功能來自動識別文字區域。 以下程式碼示範迭代每個段落,並將其座標 (X 和 Y) 列印至控制台。 :path=/static-assets/ocr/content-code-examples/how-to/read-results-output-text.cs using IronOcr; using System; using static IronOcr.OcrResult; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add image using var imageInput = new OcrImageInput("sampleText.png"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Retrieve list of detected paragraphs Paragraph[] paragraphs = ocrResult.Paragraphs; // Loop through each paragraph in the array Console.WriteLine("--- All Detected Paragraphs ---"); foreach (Paragraph paragraph in paragraphs) { // Print the text of the current paragraph Console.WriteLine(paragraph.Text); // Add a blank line for better separation (optional) Console.WriteLine(); } Imports IronOcr Imports System Imports IronOcr.OcrResult ' Instantiate IronTesseract Dim ocrTesseract As New IronTesseract() ' Add image Using imageInput As New OcrImageInput("sampleText.png") ' Perform OCR Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Retrieve list of detected paragraphs Dim paragraphs As Paragraph() = ocrResult.Paragraphs ' Loop through each paragraph in the array Console.WriteLine("--- All Detected Paragraphs ---") For Each paragraph As Paragraph In paragraphs ' Print the text of the current paragraph Console.WriteLine(paragraph.Text) ' Add a blank line for better separation (optional) Console.WriteLine() Next End Using $vbLabelText $csharpLabel 輸出 輸出會顯示對應於三個段落的三組座標。這些座標可用於繪製邊界框、抽取特定區域,或維護文字元素之間的空間關係。 OCR 結果中還有哪些其他屬性? 除了文字和文字座標外,IronOCR 還提供其他資訊。 對於每個文字元素(段落、行、詞彙和個別字元),可提供下列資訊: 文字:以字串形式顯示的實際文字。 X:從頁面左邊開始的位置,單位為像素。 Y:從頁面頂端邊緣開始的位置,單位為像素。 寬度:以像素為單位的寬度。 高度:以像素為單位的高度。 文字方向:閱讀文字的方向(從左至右或從上至下)。 位置:以像素表示此文字在頁面上位置的矩形。 這些特質在執行時尤其有用: 文字高亮與注解系統 自動偵測表單欄位 文件轉換中的版面保留 資料擷取的空間文字分析 為了進行除錯和可視化,請使用 highlight texts 功能 來直觀地驗證偵測到的區域精確度。 如何比較段落、行、詞和字? IronOCR 的階層式文字結構可讓開發人員針對其特定使用個案,在適當的細節層級上工作。 瞭解這些元素之間的差異有助於為您的應用程式選擇正確的粒度。 以下是檢測到的段落、行數、字數和字元的比較。 段落 線 Word 特點 每個粒度層級都有不同的目的: 段落:最適合文件結構分析和大量文字萃取 線條:有助於維持閱讀順序和處理表格資料 詞彙:搜尋功能和文字分析的理想選擇 字元:非常適合拼字檢查和精確的文字編輯應用程式 IronOCR 可以讀取條碼和 QR 碼嗎? 是的,IronOCR 可以讀取 BarCode 和 QR 代碼。 雖然功能可能不如 IronBarcode 強大,但 IronOCR 提供了對常見條碼類型的支援。若要啟用條碼偵測,請將 Configuration.ReadBarCodes 屬性設定為 true。 這種整合功能使 IronOCR 成為處理包含文字和 BarCode 的文件的絕佳選擇,例如發票、出貨標籤或產品目錄。 此外,還可從偵測到的 BarCode 中擷取有價值的資訊,包括格式、值、座標 (x、y)、高度、寬度和位置,作為 IronSoftware.Drawing.Rectangle 物件。 IronDrawing中的Rectangle類別允許在文件上進行精確定位。 如需更進階的條碼讀取情境,請查看我們文件中全面的 條碼讀取範例。 :path=/static-assets/ocr/content-code-examples/how-to/read-results-barcodes.cs using IronOcr; using System; using static IronOcr.OcrResult; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Enable barcodes detection ocrTesseract.Configuration.ReadBarCodes = true; // Add image using OcrInput ocrInput = new OcrInput(); ocrInput.LoadPdf("sample.pdf"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(ocrInput); // Output information to console foreach(var barcode in ocrResult.Barcodes) { Console.WriteLine("Format = " + barcode.Format); Console.WriteLine("Value = " + barcode.Value); Console.WriteLine("X = " + barcode.X); Console.WriteLine("Y = " + barcode.Y); } Console.WriteLine(ocrResult.Text); Imports IronOcr Imports System Imports IronOcr.OcrResult ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Enable barcodes detection ocrTesseract.Configuration.ReadBarCodes = True ' Add image Using ocrInput As New OcrInput() ocrInput.LoadPdf("sample.pdf") ' Perform OCR Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput) ' Output information to console For Each barcode In ocrResult.Barcodes Console.WriteLine("Format = " & barcode.Format) Console.WriteLine("Value = " & barcode.Value) Console.WriteLine("X = " & barcode.X) Console.WriteLine("Y = " & barcode.Y) Next barcode Console.WriteLine(ocrResult.Text) End Using $vbLabelText $csharpLabel Barcode 檢測輸出是什麼樣子? IronOCR 中的條碼偵測功能可與文字擷取功能無縫整合,提供包括文字內容和條碼資料的統一結果。 這種雙重能力對於自動化文件處理工作流程非常有價值,因為在這些流程中,兩種資訊類型都需要萃取與關聯。 輸出結果展示了 IronOCR 同時偵測多種條碼類型的能力,為每個偵測到的條碼提供格式識別 (例如 QRCode 或 EAN8)、解碼值和精確的座標資訊。 這些全面的資料可讓開發人員建立複雜的文件處理應用程式,有效率地處理混合的內容類型。 常見問題解答 OcrResult 物件包含哪些資訊? IronOCR 的 OcrResult 物件包含擷取的文字以及詳細的元資料,包括精確的 X/Y 座標、尺寸 (寬度與高度)、文字方向 (從左至右或從上至下),以及以段落、行、字詞和每個偵測元素的個別字元組織的層級結構。 如何從 OCR 結果中快速擷取第一個字? 您可以使用 IronOCR 的 Read 方法並存取 Words 集合來擷取第一個字的文字: `string wordText = new IronTesseract().Read("file.jpg").Words[0].Text;`.這可立即存取 OCR 結果中的個別字元。 OCR 結果中有哪些類型的座標資料? IronOCR 為每個偵測到的元素 (段落、行、字和字元) 提供精確的 X 和 Y 座標,以及寬度和高度尺寸。此坐標資料可透過 CropRectangle 物件存取,以實現文字元素的精確位置追蹤。 除了文字內容之外,我還能擷取元資料嗎? 是的,IronOCR 可以擷取全面的元資料,包括 PDF 和影像文件中發現的頁面、段落、行、字、符號,甚至是條碼。OcrResult 物件可存取每個元素的文字方向、層次結構和空間資訊。 哪些文件類型可以處理 OCR 結果? IronOCR 可以處理各種文件類型,包括掃描文件、照片、螢幕截圖、PDF 和影像檔案。讀取方法在這些格式中運作一致,返回相同結構的 OcrResult 物件,並包含完整的元資料。 擷取的文字在結果中如何組織? IronOCR 以反映自然文件組織的層次結構來組織擷取的文字。OcrResult 物件會以不同的粒度層級呈現內容 - 從整頁到個別字元 - 讓您可以輕鬆地在適當的層級處理文字,以符合您的應用程式。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 準備好開始了嗎? Nuget 下載 5,384,824 | 版本: 2026.2 剛剛發布 免費 NuGet 下載 總下載量:5,384,824 查看許可證