跳過到頁腳內容
使用 IRONOCR

發票 OCR API 開發者教學

發票 OCR API 利用機器學習技術自動提取發票數據,消除手動輸入錯誤,同時準確地從電子文件和掃描文件中捕獲供應商詳細資訊、發票號碼和價格。 本教學課程示範如何使用IronOCR建立發票 OCR 解決方案。

透過利用機器學習和電腦視覺技術,發票 OCR 技術將發票資料轉換為可供自動處理的格式。 您將學習如何應對常見的挑戰,例如手動資料輸入延遲、成本和錯誤,同時準確地從任何發票格式中提取供應商資訊、發票號碼和價格。

本文使用了IronOCR ,這是一款領先的針對.NET開發人員的發票 OCR API。

IronOCR是什麼?

IronOCR由Iron Software開發,為開發人員提供全面的 OCR 工具。 它利用機器學習和電腦視覺技術從掃描文件、圖像和 PDF 中提取文本,以實現自動化處理。 其 API 可與各種語言和平台無縫集成,減少人工資料輸入錯誤,提高效率。 提取的數據直接流入現有系統進行分析和決策。 影像預處理條碼識別和靈活的檔案解析等功能增強了其多功能性。 IronOCR使開發人員能夠將強大的文字辨識功能整合到他們的應用程式中。

該庫透過專門的語言包支援125 種國際語言,使其成為全球發票處理的理想選擇。 高級功能包括電腦視覺技術,可自動找到文本,這對於佈局各異的發票尤其有用。 此外, IronOCR還提供多執行緒處理功能,可有效處理大量發票處理。

為什麼我應該使用IronOCR進行發票處理?

IronOCR為發票處理應用提供了顯著優勢。 首先,它透過其優化的Tesseract 5 引擎提供卓越的精度,該引擎專門針對.NET應用程式進行了增強。 圖書館可以處理各種發票格式,從掃描文件PDF 文件,甚至是低品質掃描件

內建影像最佳化濾鏡可在處理前自動增強影像質量,從而實現更準確的文字擷取。 對於有特殊要求的發票, IronOCR支援自訂語言訓練,可針對發票類型中常見的獨特字體或格式進行最佳化。

IronOCR與其他 OCR 庫有何不同?

IronOCR 的獨特之處在於其簡單的單行 OCR 功能,同時又具備企業級功能。 與原始的 Tesseract 實作不同, IronOCR提供了一個託管的.NET API,可以無縫地處理複雜的操作。 該程式庫為各種文件類型提供專門的文件讀取方法,包括專門支援讀取文件中的表格,這對於發票明細項目至關重要。

篩選精靈會自動確定特定發票影像的最佳預處理設置,從而消除優化過程中的猜測。 IronOCR還提供全面的調試功能,使開發人員能夠視覺化 OCR 引擎所看到的內容,並有效地排除提取問題。

我需要哪些先決條件?

在使用IronOCR之前,請確保滿足以下先決條件:

  1. 已安裝諸如 Visual Studio 之類的整合開發環境 (IDE),並具備合適的開發環境。
  2. 具備C#程式設計基礎知識,能夠有效地理解並修改程式碼範例。
  3. 透過NuGet套件管理器或命令列將IronOCR庫安裝到您的專案中

滿足這些先決條件後,您就可以成功地開始使用IronOCR了。

IronOCR提供適用於WindowsLinuxmacOS的全面設定指南。 該程式庫支援雲端部署,並針對AWS LambdaAzure Functions提供了專門的教程。

我該使用哪個版本的 Visual Studio?

IronOCR支援 Visual Studio 2017 及最新版本。 為了獲得最佳相容性並能使用最新的 C# 功能,建議使用 Visual Studio 2019 或 2022。 該程式庫與.NET Framework、 .NET Core和.NET 5+完全相容,確保您的開發環境具有靈活性。

對於跨平台開發,具有 C# 擴充功能的 Visual Studio Code 效果很好。 行動開發人員可以利用 IronOCR 針對AndroidiOS實現的指導,使其適用於.NET MAUI應用程式

我需要具備怎樣的 C# 知識水準?

具備中級 C# 知識即可實現基本的發票 OCR 功能。 你應該能夠適應:

IronOCR 直覺的 API 設計意味著無需具備影像處理或機器學習方面的深厚專業知識。 該庫在內部處理複雜的操作,讓您可以專注於業務邏輯。 初學者可以從簡單的OCR範例入手。

如何建立一個新的 Visual Studio 專案?

要開始使用IronOCR,請先建立一個新的 Visual Studio 專案。

開啟 Visual Studio,轉到"檔案",將滑鼠懸停在"新建"上,然後按一下"專案"。

Visual Studio IDE 顯示 新專案

在新視窗中,選擇"控制台應用程式",然後按一下"下一步"。

Visual Studio 的"建立新專案"對話方塊顯示了各種專案模板,其中"控制台應用程式"選項突出顯示,用於建立適用於發票 OCR 處理的.NET Core命令列應用程式。 控制台應用程式

一個新的視窗出現。 請輸入項目名稱和地點,然後按一下"下一步"。

Visual Studio 新建專案配置窗口,顯示名為 專案配置

最後,選​​擇目標框架並點擊"建立"。

Visual Studio 專案建立精靈顯示了 目標框架

你的新 Visual Studio 專案已準備就緒。 我們來安裝IronOCR。

哪種專案類型最適合 OCR 應用?

雖然本教程為了簡單起見使用了控制台應用程序,但IronOCR支援多種項目類型:

-控制台應用程式:非常適合批次處理或命令列工具

  • Web 應用程式:非常適合建立 API 或基於 Web 的服務
  • Windows Forms/WPF :適用於具有圖形使用者介面的桌面應用程式
  • .NET MAUI應用:用於跨平台解決方案

對於大批量處理,可以考慮在 Windows 服務或微服務架構中實作IronOCR 。 圖書館的進度追蹤功能使監控長時間運作的操作變得容易。

我該選擇哪個.NET Framework版本?

IronOCR與.NET版本具有廣泛的兼容性。 對於新項目,建議使用.NET 6.0 或更高版本以獲得最佳效能和最新功能。 該庫保持了出色的向後相容性:

  • .NET Framework 4.6.2+ :適用於傳統企業應用程式
  • .NET Core 3.1 :長期支持,實現穩定部署
  • .NET 5.0+ :效能提升的現代化框架
  • .NET Standard 2.0 :跨平台最大程度的相容性

部署到Docker 容器時, .NET 6.0 或更高版本可提供更小的映像大小和更好的效能。 Azure Functions同時支援.NET 6.0 和.NET Framework 。

如何安裝IronOCR?

下載和安裝IronOCR有兩種簡單的方法:

  1. 使用 Visual Studio NuGet套件管理器
  2. 使用 Visual Studio 命令列

何時應該使用NuGet套件管理器,何時應該使用命令列?

根據您的工作流程,選擇使用NuGet套件管理器圖形使用者介面 (GUI) 或命令列:

NuGet套件管理器 GUI在下列情況下效果最佳: 您是NuGet包的新手 您想瀏覽IronOCR語言包 您更喜歡視覺確認 您管理多個包裹

命令列(軟體包管理器控制台)在以下情況下表現出色: 您熟悉命令列介面

  • 您遵循腳本化部署 您需要快速取得特定版本。
  • 您使用了進階安裝選項

兩種方法都能達到相同的效果-根據舒適度和需求選擇即可。

我可能還需要哪些額外的語言包?

IronOCR透過專用軟體包支援125 種國際語言。 發票處理時,請考慮以下事項:

-特定業務包:財務文件的財務語言包 -區域語言:依發票來源而定(西班牙語、法語、德語) -多語言支援:適用於包含多種語言的發票 -自訂語言:用於特殊字體或自訂訓練數據

語言包與IronOCR主程式包一起安裝,可顯著提高非英語文字的辨識準確率。

使用 Visual Studio NuGet套件管理器

使用 Visual Studio NuGet套件管理器將IronOCR整合到您的 C# 專案中。

導覽至"工具" > "NuGet套件管理器" > "管理解決方案的NuGet套件"。

Visual Studio IDE 顯示NuGet套件管理器介面,其中包含IronOCR套件的搜尋結果,並顯示用於設定發票 OCR 功能的安裝選項和套件詳細資訊 NuGet套件管理器

搜尋IronOCR並將其安裝到您的專案中。

 NuGet套件管理器介面,顯示IronOCR v2022.1.0 及相關語言包,包括阿拉伯語、希伯來語和西班牙語 OCR 功能,以及每個專用識別包的版本號和描述@ 在NuGet套件管理器介面中選擇IronOCR套件。

使用相同的方法安裝其他語言套件。

使用 Visual Studio 命令列

  1. 在 Visual Studio 中,前往"工具" > "NuGet套件管理器" > "套件管理器控制台"。
  2. 在軟體包管理器控制台中輸入以下命令:

    Install-Package IronOcr

Visual Studio 套件管理器控制台顯示 軟體包管理器控制台

該軟體包將下載並安裝到您目前的專案中,即可使用。

如何使用IronOCR從發票中提取資料?

使用IronOCR ,只需幾行程式碼即可輕鬆提取發票資料。 它取代了手動資料錄入,簡化了您的工作流程。

以下是一個用於文字提取的發票範例:

Sample invoice document displaying customer details, invoice number INV/2023/00039, three line items for cleaning services totaling $80.50, demonstrating a typical invoice format for OCR extraction 發票範本

讓我們從這張發票中提取所有資料:

using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
// This is the main OCR engine that will process our invoice
var ocr = new IronTesseract();

// Configure OCR settings for better invoice processing
ocr.Configuration.BlackListCharacters = "~`$#^*_}{]___PROTECTED_LINK_48___ method from ___PROTECTED_LINK_49___ class. Key enhancements include:

- **Image preprocessing**: ___PROTECTED_LINK_50___ corrects tilted scans; ___PROTECTED_LINK_51___ removes artifacts
- **Resolution enhancement**: Setting ___PROTECTED_LINK_52___ improves recognition
- **Character blacklisting**: Prevents common OCR misinterpretations
- **Confidence scoring**: Assesses extraction reliability

!___PROTECTED_LINK_53___
**Invoice Parser**

### How Do I Handle Different Invoice Formats?

Invoice formats vary between vendors, but IronOCR provides flexible solutions:

1. **Template-based**: Define ___PROTECTED_LINK_54___
2. **Computer vision**: Use ___PROTECTED_LINK_55___ to locate text
3. **Table extraction**: Leverage ___PROTECTED_LINK_56___ for line items
4. **Multi-format**: Process ___PROTECTED_LINK_57___, ___PROTECTED_LINK_58___, and ___PROTECTED_LINK_59___

For complex layouts, implement the ___PROTECTED_LINK_60___ which uses machine learning to identify structures automatically.

### What Are Common Extraction Patterns for Invoice Data?

Invoice data follows recognizable patterns extractable using regular expressions with OCR results:

```csharp
using IronOcr;
using System;
using System.Text.`RegularExpressions`;
using System.Collections.Generic;

public class `InvoiceDataExtractor`
{
    private readonly `IronTesseract` ocr;

    public `InvoiceDataExtractor`()
    {
        ocr = new `IronTesseract`();
        // Configure for optimal invoice reading
        `ocr.Configuration`.`ReadBarcodes` = true; // Many invoices include barcodes
        `ocr.Configuration`.`TesseractVersion` = `TesseractVersion`.Tesseract5;
    }

    public `InvoiceData` `ExtractInvoiceData`(string imagePath)
    {
        var invoiceData = new `InvoiceData`();

        using (var input = new `OcrInput`(imagePath))
        {
            // Apply filters for better accuracy
            input.`EnhanceResolution`(300);
            `input.Sharpen`();

            var result = `ocr.Read`(input);
            var text = `result.Text`;

            // Extract invoice number
            invoiceData.`InvoiceNumber` = `ExtractPattern`(text, 
                @"INV[/-]?\d{4}[/-]?\d{5}|Invoice\s*#?\s*:?\s*(\d+)");

            // Extract dates
            invoiceData.`InvoiceDate` = `ExtractDate`(text, 
                @"Invoice\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");
            invoiceData.`DueDate` = `ExtractDate`(text, 
                @"Due\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");

            // Extract amounts
            `invoiceData.Total` = `ExtractAmount`(text, 
                @"Total\s*:?\s*\$?\s*([\d,]+\.?\d*)");
            `invoiceData.Tax` = `ExtractAmount`(text, 
                @"Tax\s*:?\s*\$?\s*([\d,]+\.?\d*)");

            // Extract vendor information
            invoiceData.`VendorName` = `ExtractVendorName`(text);

            // Extract line items using table detection
            invoiceData.`LineItems` = `ExtractLineItems`(result);

            // Extract any barcodes found
            if (`result.Barcodes`.Length > 0)
            {
                invoiceData.`BarcodeValues` = new List<string>();
                foreach (var barcode in `result.Barcodes`)
                {
                    invoiceData.`BarcodeValues`.Add(`barcode.Value`);
                }
            }
        }

        return invoiceData;
    }

    private string `ExtractPattern`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        return `match.Success` ? `match.Value` : `string.Empty`;
    }

    private `DateTime`? `ExtractDate`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            if (`DateTime`.`TryParse`(`match.Groups`[1].Value, out `DateTime` date))
                return date;
        }
        return null;
    }

    private decimal `ExtractAmount`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            var amountStr = `match.Groups`[1].Value.Replace(",", "");
            if (decimal.`TryParse`(amountStr, out decimal amount))
                return amount;
        }
        return 0;
    }

    private string `ExtractVendorName`(string text)
    {
        // Usually the vendor name appears in the first few lines
        var lines = `text.Split`('\n');
        if (`lines.Length` > 0)
        {
            // Simple heuristic: first non-empty line that's not a common header
            foreach (var line in lines)
            {
                var trimmed = `line.Trim`();
                if (!string.`IsNullOrEmpty`(trimmed) && 
                    !trimmed.`ToLower`().Contains("invoice") &&
                    `trimmed.Length` > 3)
                {
                    return trimmed;
                }
            }
        }
        return `string.Empty`;
    }

    private List<`LineItem`> `ExtractLineItems`(`OcrResult` result)
    {
        var lineItems = new List<`LineItem`>();

        // Use IronOCR's table detection capabilities
        if (`result.Tables` != null && `result.Tables`.Count > 0)
        {
            foreach (var table in `result.Tables`)
            {
                // Process each row as a potential line item
                for (int i = 1; i < table.`RowCount`; i++) // Skip header row
                {
                    var item = new `LineItem`
                    {
                        Description = table[i, 0]?.Text ?? "",
                        Quantity = `ParseQuantity`(table[i, 1]?.Text),
                        `UnitPrice` = `ParseAmount`(table[i, 2]?.Text),
                        Total = `ParseAmount`(table[i, 3]?.Text)
                    };

                    if (!string.`IsNullOrEmpty`(`item.Description`))
                        `lineItems.Add`(item);
                }
            }
        }

        return lineItems;
    }

    private int `ParseQuantity`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d]", "");
        return int.`TryParse`(cleaned, out int qty) ? qty : 0;
    }

    private decimal `ParseAmount`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d.]", "");
        return decimal.`TryParse`(cleaned, out decimal amt) ? amt : 0;
    }
}

// Data classes for structured invoice information
public class `InvoiceData`
{
    public string `InvoiceNumber` { get; set; }
    public `DateTime`? `InvoiceDate` { get; set; }
    public `DateTime`? `DueDate` { get; set; }
    public string `VendorName` { get; set; }
    public decimal Total { get; set; }
    public decimal Tax { get; set; }
    public List<`LineItem`> `LineItems` { get; set; }
    public List<string> `BarcodeValues` { get; set; }
}

public class `LineItem`
{
    public string Description { get; set; }
    public int Quantity { get; set; }
    public decimal `UnitPrice` { get; set; }
    public decimal Total { get; set; }
}
using IronOcr;
using System;

// Initialize a new instance of the IronTesseract class
// This is the main OCR engine that will process our invoice
var ocr = new IronTesseract();

// Configure OCR settings for better invoice processing
ocr.Configuration.BlackListCharacters = "~`$#^*_}{]___PROTECTED_LINK_48___ method from ___PROTECTED_LINK_49___ class. Key enhancements include:

- **Image preprocessing**: ___PROTECTED_LINK_50___ corrects tilted scans; ___PROTECTED_LINK_51___ removes artifacts
- **Resolution enhancement**: Setting ___PROTECTED_LINK_52___ improves recognition
- **Character blacklisting**: Prevents common OCR misinterpretations
- **Confidence scoring**: Assesses extraction reliability

!___PROTECTED_LINK_53___
**Invoice Parser**

### How Do I Handle Different Invoice Formats?

Invoice formats vary between vendors, but IronOCR provides flexible solutions:

1. **Template-based**: Define ___PROTECTED_LINK_54___
2. **Computer vision**: Use ___PROTECTED_LINK_55___ to locate text
3. **Table extraction**: Leverage ___PROTECTED_LINK_56___ for line items
4. **Multi-format**: Process ___PROTECTED_LINK_57___, ___PROTECTED_LINK_58___, and ___PROTECTED_LINK_59___

For complex layouts, implement the ___PROTECTED_LINK_60___ which uses machine learning to identify structures automatically.

### What Are Common Extraction Patterns for Invoice Data?

Invoice data follows recognizable patterns extractable using regular expressions with OCR results:

```csharp
using IronOcr;
using System;
using System.Text.`RegularExpressions`;
using System.Collections.Generic;

public class `InvoiceDataExtractor`
{
    private readonly `IronTesseract` ocr;

    public `InvoiceDataExtractor`()
    {
        ocr = new `IronTesseract`();
        // Configure for optimal invoice reading
        `ocr.Configuration`.`ReadBarcodes` = true; // Many invoices include barcodes
        `ocr.Configuration`.`TesseractVersion` = `TesseractVersion`.Tesseract5;
    }

    public `InvoiceData` `ExtractInvoiceData`(string imagePath)
    {
        var invoiceData = new `InvoiceData`();

        using (var input = new `OcrInput`(imagePath))
        {
            // Apply filters for better accuracy
            input.`EnhanceResolution`(300);
            `input.Sharpen`();

            var result = `ocr.Read`(input);
            var text = `result.Text`;

            // Extract invoice number
            invoiceData.`InvoiceNumber` = `ExtractPattern`(text, 
                @"INV[/-]?\d{4}[/-]?\d{5}|Invoice\s*#?\s*:?\s*(\d+)");

            // Extract dates
            invoiceData.`InvoiceDate` = `ExtractDate`(text, 
                @"Invoice\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");
            invoiceData.`DueDate` = `ExtractDate`(text, 
                @"Due\s*Date\s*:?\s*(\d{1,2}[/-]\d{1,2}[/-]\d{2,4})");

            // Extract amounts
            `invoiceData.Total` = `ExtractAmount`(text, 
                @"Total\s*:?\s*\$?\s*([\d,]+\.?\d*)");
            `invoiceData.Tax` = `ExtractAmount`(text, 
                @"Tax\s*:?\s*\$?\s*([\d,]+\.?\d*)");

            // Extract vendor information
            invoiceData.`VendorName` = `ExtractVendorName`(text);

            // Extract line items using table detection
            invoiceData.`LineItems` = `ExtractLineItems`(result);

            // Extract any barcodes found
            if (`result.Barcodes`.Length > 0)
            {
                invoiceData.`BarcodeValues` = new List<string>();
                foreach (var barcode in `result.Barcodes`)
                {
                    invoiceData.`BarcodeValues`.Add(`barcode.Value`);
                }
            }
        }

        return invoiceData;
    }

    private string `ExtractPattern`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        return `match.Success` ? `match.Value` : `string.Empty`;
    }

    private `DateTime`? `ExtractDate`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            if (`DateTime`.`TryParse`(`match.Groups`[1].Value, out `DateTime` date))
                return date;
        }
        return null;
    }

    private decimal `ExtractAmount`(string text, string pattern)
    {
        var match = Regex.Match(text, pattern, `RegexOptions`.`IgnoreCase`);
        if (`match.Success` && `match.Groups`.Count > 1)
        {
            var amountStr = `match.Groups`[1].Value.Replace(",", "");
            if (decimal.`TryParse`(amountStr, out decimal amount))
                return amount;
        }
        return 0;
    }

    private string `ExtractVendorName`(string text)
    {
        // Usually the vendor name appears in the first few lines
        var lines = `text.Split`('\n');
        if (`lines.Length` > 0)
        {
            // Simple heuristic: first non-empty line that's not a common header
            foreach (var line in lines)
            {
                var trimmed = `line.Trim`();
                if (!string.`IsNullOrEmpty`(trimmed) && 
                    !trimmed.`ToLower`().Contains("invoice") &&
                    `trimmed.Length` > 3)
                {
                    return trimmed;
                }
            }
        }
        return `string.Empty`;
    }

    private List<`LineItem`> `ExtractLineItems`(`OcrResult` result)
    {
        var lineItems = new List<`LineItem`>();

        // Use IronOCR's table detection capabilities
        if (`result.Tables` != null && `result.Tables`.Count > 0)
        {
            foreach (var table in `result.Tables`)
            {
                // Process each row as a potential line item
                for (int i = 1; i < table.`RowCount`; i++) // Skip header row
                {
                    var item = new `LineItem`
                    {
                        Description = table[i, 0]?.Text ?? "",
                        Quantity = `ParseQuantity`(table[i, 1]?.Text),
                        `UnitPrice` = `ParseAmount`(table[i, 2]?.Text),
                        Total = `ParseAmount`(table[i, 3]?.Text)
                    };

                    if (!string.`IsNullOrEmpty`(`item.Description`))
                        `lineItems.Add`(item);
                }
            }
        }

        return lineItems;
    }

    private int `ParseQuantity`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d]", "");
        return int.`TryParse`(cleaned, out int qty) ? qty : 0;
    }

    private decimal `ParseAmount`(string text)
    {
        if (string.`IsNullOrEmpty`(text)) return 0;
        var cleaned = Regex.Replace(text, @"[^\d.]", "");
        return decimal.`TryParse`(cleaned, out decimal amt) ? amt : 0;
    }
}

// Data classes for structured invoice information
public class `InvoiceData`
{
    public string `InvoiceNumber` { get; set; }
    public `DateTime`? `InvoiceDate` { get; set; }
    public `DateTime`? `DueDate` { get; set; }
    public string `VendorName` { get; set; }
    public decimal Total { get; set; }
    public decimal Tax { get; set; }
    public List<`LineItem`> `LineItems` { get; set; }
    public List<string> `BarcodeValues` { get; set; }
}

public class `LineItem`
{
    public string Description { get; set; }
    public int Quantity { get; set; }
    public decimal `UnitPrice` { get; set; }
    public decimal Total { get; set; }
}
$vbLabelText   $csharpLabel

發票處理:從發票中提取特定數據

使用以下代碼提取特定發票數據,例如客戶發票號碼:

using IronOcr;
using System;
using System.Text.`RegularExpressions`;

// Initialize a new instance of the `IronTesseract` class
var ocr = new `IronTesseract`();

// Use the `OcrInput` object to load the image file
using (var input = new `OcrInput`(@"`r2.png`"))
{
    // Perform OCR on the image
    var result = `ocr.Read`(input);

    // Define a regular expression pattern for the invoice number
    var linePattern = @"INV\/\d{4}\/\d{5}";

    // Match the pattern in the extracted text
    var lineMatch = Regex.Match(`result.Text`, linePattern);

    // Check if the pattern matches any part of the text
    if (`lineMatch.Success`)
    {
        // If a match is found, print the invoice number
        var lineValue = `lineMatch.Value`;
        Console.`WriteLine`("Customer Invoice number: " + lineValue);
    }
}
using IronOcr;
using System;
using System.Text.`RegularExpressions`;

// Initialize a new instance of the `IronTesseract` class
var ocr = new `IronTesseract`();

// Use the `OcrInput` object to load the image file
using (var input = new `OcrInput`(@"`r2.png`"))
{
    // Perform OCR on the image
    var result = `ocr.Read`(input);

    // Define a regular expression pattern for the invoice number
    var linePattern = @"INV\/\d{4}\/\d{5}";

    // Match the pattern in the extracted text
    var lineMatch = Regex.Match(`result.Text`, linePattern);

    // Check if the pattern matches any part of the text
    if (`lineMatch.Success`)
    {
        // If a match is found, print the invoice number
        var lineValue = `lineMatch.Value`;
        Console.`WriteLine`("Customer Invoice number: " + lineValue);
    }
}
$vbLabelText   $csharpLabel

Visual Studio 偵錯控制台顯示已成功建立 PDF 文件,其中客戶發票號碼 INV/2023/00039 已使用IronOCR提取,確認 OCR 流程已完成且無錯誤。 發票掃描

對於複雜的提取場景,請使用專門的 OCR 配置來最佳化您的發票類型。 OcrResult類別提供有關每個已識別元素的詳細信息,包括座標和用於驗證的置信度分數。

發票OCR API的主要優點是什麼?

IronOCR 的發票 OCR API 透過機器學習和電腦視覺技術改變了發票處理方式。 這項技術將發票文字轉換為機器可讀格式,簡化了資料擷取,以便於分析、整合和流程改進。 它為發票處理提供​​強大的自動化功能,提高準確性並優化應付帳款等工作流程。

IronOCR利用優化的 Tesseract 結果,無需額外配置即可提供卓越的精度。 它支援多頁框架 TIFFPDF 文件以及所有流行的圖像格式。 從圖像中讀取條碼增加了另一個提取維度。

發票處理的主要優點:

1.節省時間:將數小時縮短至數秒 2.準確度:透過置信度評分最大限度地減少誤差 3.可擴展性:利用多執行緒處理數千個行程 4.整合:匯出為可搜尋的 PDF結構化格式 5.降低成本:降低營運成本

該程式庫部署靈活,可整合到現有系統中—本地部署、雲端部署或混合部署。 IronOCR支援DockerAzureAWS ,可根據您的需求進行擴充。

生產環境可受益於 IronOCR 的許可選項,包括專門的支援和定期更新。 庫中的故障排除指南工程支援可確保順利實施。

請造訪主頁以了解更多關於IronOCR 的資訊。 有關發票 OCR 的更多教程,請參閱這份詳細的發票 OCR 指南。 要了解如何使用電腦視覺技術識別發票字段,請查看這篇電腦視覺教學

常見問題解答

我如何使用 OCR 自動化發票數據處理?

您可以使用 IronOCR 通過其機器學習算法自動化發票數據處理。IronOCR 從數字和掃描的發票中提取如供應商信息、發票號碼和價格等詳細信息,減少手動輸入錯誤並提高效率。

設置發票 OCR API 涉及哪些步驟?

要使用 IronOCR 設置發票 OCR API,首先通過 Visual Studio 的 NuGet Package Manager 下載並安裝庫。接下來,創建一個新的 C# 項目,集成 IronOCR,並使用其方法加載和讀取圖像文件以進行文本提取。

IronOCR 可以提取發票號碼等特定數據嗎?

是的,IronOCR 可以提取如發票號碼等特定數據。它利用正則表達式來匹配提取文本中的模式,允許您從發票中提取特定信息。

IronOCR 有哪些有利於發票處理的功能?

IronOCR 包含如圖像預處理、條形碼識別和文件解析等功能。這些功能增強了其從各種發票格式中準確提取和處理文本的能力,提高了數據捕獲和工作流效率。

圖像預處理如何改善 OCR 結果?

IronOCR 的圖像預處理通過在文本提取之前優化圖像質量來改善 OCR 結果。這包括如對比度調整和噪聲消除等操作,能夠從發票中更準確地提取數據。

是否可以同時使用 IronOCR 處理數字和掃描的發票?

是的,IronOCR 能夠處理數字和掃描的發票。它利用先進的機器學習和計算機視覺技術從各種格式和圖像質量中準確提取文本。

IronOCR 如何處理多頁格式和文件類型?

IronOCR 支持多頁格式和流行的圖像和 PDF 文件類型。它能有效地從複雜文檔中提取文本,使其在各種發票處理應用中非常多才多藝。

開發人員在哪裡可以找到使用 IronOCR 的教程?

開發人員可以在 IronOCR 網站上找到教程和額外資源。該網站提供了一系列學習材料,包括操作指南和博客文章,應用於不同場景中的 IronOCR。

Kannaopat Udonpant
軟體工程師
在成為軟件工程師之前,Kannapat 從日本北海道大學完成了環境資源博士學位。在追逐學位期间,Kannapat 還成為了生產工程系一部份——汽車机器人實验室的成員。2022 年,他利用他的 C# 技能加入 Iron Software 的工程團隊, 專注於 IronPDF。Kannapat 珍惜他的工作,因為他直接向编写大部分 IronPDF 使用的代碼的開發者学习。除了同行学习,Kannapat 还喜欢在 Iron Software 工作的社交十环。当他不编写代碼或文檔時,Kannapat 通常在他的 PS5 上打游戏或重看《The Last of Us》。

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me