跳過到頁腳內容
使用 IRONOCR

如何使用 C# 中的 OCR 從收據中提取數據

IronOCR 提供了一個強大的 C# 庫,使用先進的 OCR 技術從收據圖像中提取文本,支援 125 種語言和內建圖像預處理功能,可實現自動費用追蹤和數據分析。

收據和自動化

在如今快節奏的生活中, 收據至關重要。 無論你是購買食品雜貨還是外出用餐,收據都能幫助你追蹤支出並進行預算。 同時,商店使用收據掃描器分析銷售數據,透過數據提取技術幫助他們預測需求和管理庫存。

然而,收據可能難以辨認,計算結果也不總是清晰明了。 手動輸入預算資料既繁瑣又容易出錯,尤其是在專案很多的情況下。 遺失收據可能會讓你的每月超支變成一個謎。 傳統紙質收據經常存在列印品質不佳、油墨褪色和熱敏紙老化等問題,因此OCR 影像優化對於準確提取至關重要。

為了解決這個問題,預算和財務應用程式採用了OCR (光學字元辨識)技術。 透過將收據掃描成數位格式,OCR 可以最大限度地減少錯誤,自動輸入數據,追蹤支出,並揭示購買模式。 現代OCR 解決方案可處理各種收據格式,從傳統的銷售點列印輸出到具有條碼和二維碼讀取功能的數位收據。

OCR利用機器學習技術從圖像中辨識和提取文字。 該過程包括影像預處理、字元分割、模式識別和驗證。 然而,OCR 並非完美無缺——模糊或污跡會導致錯誤。 先進系統利用電腦視覺技術來提高準確率。 選擇一個可靠的、能夠高效處理和最佳化讀取的 OCR 庫對於成功實現文件自動化至關重要。

為什麼我應該選擇 IronOCR 進行收據處理?

IronOCR是一個基於客製化Tesseract OCR 引擎的 C# 函式庫。與標準 Tesseract 不同,IronOCR 包含了Tesseract 5 的最佳化和專為 .NET 開發人員設計的功能。 它之所以脫穎而出,是因為它具備以下特質:

1.跨平台相容性:可與 .NET 8、7、6、5 和 Framework 4.6.2+ 搭配使用。 可在 Windows、macOS、Azure 和 Linux 系統上運作。 可無縫部署至DockerAWS LambdaAzure Functions

2.靈活性和可擴展性:支援 JPG、PNG 和 GIF 格式。 與 System.Drawing 物件整合。 處理多頁 TIFFPDF 串流。 支援 多線程,適用於高吞吐量場景。

3.易用性和支援:文件齊全,API 功能強大,並提供 24/5 支援。 提供簡單的單行操作詳細的配置選項。 包含全面的故障排除指南

4.多語言功能:支援125 種國際語言。 能夠有效識別產品名稱和價格。 支援每個文件使用多種語言。 支援自訂訓練資料檔

5.進階影像處理:內建濾鏡可自動增強收據品質。 包括降噪方向校正DPI 優化篩選精靈會自動決定最佳設定。

如何在我的應用程式中實現收據OCR?

我需要什麼許可證才能開始?

使用 IronOCR 之前,您需要一個許可證金鑰。 點這裡獲取免費試用。 授權選項包括 Lite、Plus 和 Professional 三個級別,分別適用於不同的團隊規模和部署場景。 請參閱有關應用許可證密鑰的文件。

// 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"
$vbLabelText   $csharpLabel

對於 Web 應用程序,請在 Web.config 中設定許可證金鑰以進行集中配置。 隨著您的業務發展,授權系統支援擴展和升級

如何使用 IronOCR 讀取超市收據?

讓我們探索如何在應用程式中使用 IronOCR,該應用程式可以使用智慧型手機掃描超市收據,提取產品名稱和價格,並根據購買情況獎勵忠誠度積分。 這包括影像擷取、預處理、OCR執行以及使用結果置信度評分進行資料驗證。

典型的收據圖片是什麼樣的?

這是一個超市收據範例,其中包含佔位符文字(Lorem ipsum),以及商品、價格、小計(107.60 美元)和付款詳情——展示了典型的收據佈局,包括抬頭、商品列表、總計和條碼。

常見的收據問題包括熱感紙品質、字體不統一、版面擁擠以及折疊或受潮造成的損壞。 IronOCR 的預處理透過影像品質校正色彩校正技術來處理這些問題。

我需要編寫哪些 C# 程式碼來提取收據資料?

using IronOcr;

class ReceiptScanner
{
    static void Main()
    {
        // Set the license key for IronOCR
        IronOcr.License.LicenseKey = "YOUR-KEY";

        // Instantiate OCR engine with optimal settings for receipts
        var ocr = new IronTesseract();

        // Configure for receipt-specific text
        ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.$,- ";
        ocr.Configuration.BlackListCharacters = "~`@#%^*_+={}[]|\\:;\"'<>?";

        using var inputPhoto = new OcrInput();
        inputPhoto.LoadImage("supermarketexample.jpg");

        // Apply preprocessing for better accuracy
        inputPhoto.DeNoise();
        inputPhoto.ToGrayScale();
        inputPhoto.Contrast(1.2);

        // Perform OCR on the loaded image
        OcrResult result = ocr.Read(inputPhoto);

        // Output the text extracted from the receipt
        string text = result.Text;
        Console.WriteLine(text);

        // Extract specific data using OcrResult features
        foreach (var line in result.Lines)
        {
            if (line.Text.Contains("TOTAL"))
            {
                Console.WriteLine($"Total Found: {line.Text}");
            }
        }
    }
}
using IronOcr;

class ReceiptScanner
{
    static void Main()
    {
        // Set the license key for IronOCR
        IronOcr.License.LicenseKey = "YOUR-KEY";

        // Instantiate OCR engine with optimal settings for receipts
        var ocr = new IronTesseract();

        // Configure for receipt-specific text
        ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.$,- ";
        ocr.Configuration.BlackListCharacters = "~`@#%^*_+={}[]|\\:;\"'<>?";

        using var inputPhoto = new OcrInput();
        inputPhoto.LoadImage("supermarketexample.jpg");

        // Apply preprocessing for better accuracy
        inputPhoto.DeNoise();
        inputPhoto.ToGrayScale();
        inputPhoto.Contrast(1.2);

        // Perform OCR on the loaded image
        OcrResult result = ocr.Read(inputPhoto);

        // Output the text extracted from the receipt
        string text = result.Text;
        Console.WriteLine(text);

        // Extract specific data using OcrResult features
        foreach (var line in result.Lines)
        {
            if (line.Text.Contains("TOTAL"))
            {
                Console.WriteLine($"Total Found: {line.Text}");
            }
        }
    }
}
Imports IronOcr

Class ReceiptScanner
    Shared Sub Main()
        ' Set the license key for IronOCR
        IronOcr.License.LicenseKey = "YOUR-KEY"

        ' Instantiate OCR engine with optimal settings for receipts
        Dim ocr As New IronTesseract()

        ' Configure for receipt-specific text
        ocr.Configuration.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.$,- "
        ocr.Configuration.BlackListCharacters = "~`@#%^*_+={}[]|\:;""'<>?"

        Using inputPhoto As New OcrInput()
            inputPhoto.LoadImage("supermarketexample.jpg")

            ' Apply preprocessing for better accuracy
            inputPhoto.DeNoise()
            inputPhoto.ToGrayScale()
            inputPhoto.Contrast(1.2)

            ' Perform OCR on the loaded image
            Dim result As OcrResult = ocr.Read(inputPhoto)

            ' Output the text extracted from the receipt
            Dim text As String = result.Text
            Console.WriteLine(text)

            ' Extract specific data using OcrResult features
            For Each line In result.Lines
                If line.Text.Contains("TOTAL") Then
                    Console.WriteLine($"Total Found: {line.Text}")
                End If
            Next
        End Using
    End Sub
End Class
$vbLabelText   $csharpLabel

這段程式碼示範了:

  1. 導入 IronOcr 庫。
  2. 使用設定選項實例化 OCR 引擎 (IronTesseract)。
  3. 建立一個新的OcrInput來載入收據圖片。
  4. 應用預處理以提高準確度。
  5. 使用 Read 方法擷取文字。
  6. 使用OcrResult 類別處理結構化資料的結果。

IronOCR 支援讀取不同格式的收據螢幕截圖掃描文件。 它還可以從結構化收據中提取表格資料

如何驗證提取資料的準確性?

為確保一致性,檢查擷取資料的置信度。 IronOCR提供多層次的全面信賴度指標

OcrResult result = ocr.Read(inputPhoto);
string text = result.Text;
Console.WriteLine(text);
Console.WriteLine($"Overall Confidence: {result.Confidence}%");

// Check confidence for individual elements
foreach (var word in result.Words)
{
    if (word.Confidence < 80)
    {
        Console.WriteLine($"Low confidence word: '{word.Text}' ({word.Confidence}%)");
    }
}

// Validate numeric values
foreach (var block in result.Blocks)
{
    if (block.Text.Contains("$"))
    {
        Console.WriteLine($"Price detected: {block.Text} (Confidence: {block.Confidence}%)");
    }
}
OcrResult result = ocr.Read(inputPhoto);
string text = result.Text;
Console.WriteLine(text);
Console.WriteLine($"Overall Confidence: {result.Confidence}%");

// Check confidence for individual elements
foreach (var word in result.Words)
{
    if (word.Confidence < 80)
    {
        Console.WriteLine($"Low confidence word: '{word.Text}' ({word.Confidence}%)");
    }
}

// Validate numeric values
foreach (var block in result.Blocks)
{
    if (block.Text.Contains("$"))
    {
        Console.WriteLine($"Price detected: {block.Text} (Confidence: {block.Confidence}%)");
    }
}
Dim result As OcrResult = ocr.Read(inputPhoto)
Dim text As String = result.Text
Console.WriteLine(text)
Console.WriteLine($"Overall Confidence: {result.Confidence}%")

' Check confidence for individual elements
For Each word In result.Words
    If word.Confidence < 80 Then
        Console.WriteLine($"Low confidence word: '{word.Text}' ({word.Confidence}%)")
    End If
Next

' Validate numeric values
For Each block In result.Blocks
    If block.Text.Contains("$") Then
        Console.WriteLine($"Price detected: {block.Text} (Confidence: {block.Confidence}%)")
    End If
Next
$vbLabelText   $csharpLabel

Confidence 屬性衡量統計準確度,從 0(低)到 100(高)。 利用這些置信水準來決定如何處理資料。 對於生產系統,實施進度追蹤以監控 OCR 操作。

如何透過影像預處理提高OCR準確率?

處理影像前,請使用以下方法預處理影像,以獲得更好的處理效果:

using var inputPhoto = new OcrInput();
inputPhoto.LoadImage("receipt.jpg");

// Basic preprocessing
inputPhoto.DeNoise();           // Removes noise from the image
inputPhoto.ToGrayScale();       // Converts image to grayscale
inputPhoto.Contrast(1.5);       // Enhance contrast for faded receipts
inputPhoto.Sharpen();           // Improve text clarity

// Advanced preprocessing for challenging receipts
inputPhoto.Rotate(2.5);         // Correct slight rotation
inputPhoto.Deskew();            // Automatically straighten receipt
inputPhoto.Scale(200);          // Upscale low-resolution images

// Handle specific receipt issues
if (receiptIsDamaged)
{
    inputPhoto.Dilate();        // Thicken thin text
    inputPhoto.Erode();         // Reduce text bleeding
}

// For colored or patterned backgrounds
inputPhoto.Binarize();          // Convert to pure black and white
inputPhoto.Invert();            // Handle white text on dark background
using var inputPhoto = new OcrInput();
inputPhoto.LoadImage("receipt.jpg");

// Basic preprocessing
inputPhoto.DeNoise();           // Removes noise from the image
inputPhoto.ToGrayScale();       // Converts image to grayscale
inputPhoto.Contrast(1.5);       // Enhance contrast for faded receipts
inputPhoto.Sharpen();           // Improve text clarity

// Advanced preprocessing for challenging receipts
inputPhoto.Rotate(2.5);         // Correct slight rotation
inputPhoto.Deskew();            // Automatically straighten receipt
inputPhoto.Scale(200);          // Upscale low-resolution images

// Handle specific receipt issues
if (receiptIsDamaged)
{
    inputPhoto.Dilate();        // Thicken thin text
    inputPhoto.Erode();         // Reduce text bleeding
}

// For colored or patterned backgrounds
inputPhoto.Binarize();          // Convert to pure black and white
inputPhoto.Invert();            // Handle white text on dark background
$vbLabelText   $csharpLabel

這些預處理步驟可以提高提取精度。 篩選精靈會自動為您的收據找到最佳篩選組合。對於彩色背景的收據,顏色校正至關重要。

高級場景可能需要針對特定區域的 OCR來重點識別總數或稅務資訊。 對於帶有條碼的收據,啟用條碼讀取和文字擷取功能。

使用 IronOCR 進行收據處理的主要優點是什麼?

IronOCR 授權頁面顯示三個定價等級(Lite 版 749 美元,Plus 版 1,499 美元,Professional 版 2,999 美元),並提供 IronOCR 和 Iron Suite 選項之間的切換,顯示 Professional 許可詳情和總費用 5,998 美元——為團隊和企業提供靈活的定價方案,既有單獨的價格將 Suite 套裝,既有產品組合,還有更大的價格組合。

收據 OCR 技術可協助企業和個人進行預算編制、防詐騙和自動資料收集。 IronOCR 具有準確度高、速度快、易於與現有平台整合等優點,是收據掃描解決方案的理想選擇。

主要優勢包括:

1.效能最佳化:透過多執行緒速度調優,高效處理數千張收據。

2.匯出彈性:將收據轉換為可搜尋的 PDFhOCR HTML ,以便整合到 Web 中。

3.企業功能:部署到AzureDockerLinux 伺服器以實現可擴充性。

4.專業識別:閱讀收據上的手寫筆記並提取表格結構

5.調試工具:突出顯示文字視覺化結果導出功能有助於故障排除。

試用 IronOCR 的試用許可證,探索其各項功能。 全面的文件程式碼範例可協助您快速實現收據 OCR。

常見問題解答

OCR 技術如何用於自動化超市收據的處理?

光學字符識別技術可以通過將掃描的收據轉換為數字數據來自動化超市收據的處理。使用 IronOCR,收據可以被自動讀取並提取文本,減少手動數據錄入的需求並最小化人工錯誤。

IronOCR 在處理超市收據時有哪些優勢?

IronOCR 在處理超市收據時提供了一些優勢,包括跨平台兼容性、多種圖像格式支持、易於集成的強大 API 以及能夠處理多達 125 種語言,使其非常適合國際收據處理。

如何將 IronOCR 集成到 C# 應用程序中以讀取超市收據?

要將 IronOCR 集成到 C# 應用程序中,您需要獲得授權密鑰,導入 IronOcr 庫,並使用 IronTesseract 引擎從超市收據圖像中讀取和提取文本。

在收據掃描中哪些預處理技術可提高光學字符識別的準確性?

IronOCR 提供了預處理技術,如 DeNoiseToGrayScale,以提高光學字符識別的準確性。這些技術有助於去除圖像噪點並將圖像轉換為灰度,以增強從收據中提取文本的效果。

為何信心測試在光學字符識別中很重要,如何應用?

在 IronOCR 中,信心測試很重要,因為它測量了提取數據的準確性,範圍從 0(低)到 1(高)。它幫助用戶評估光學字符識別結果的可靠性並指導數據處理決策。

IronOCR 能否處理多語言超市收據?

是的,IronOCR 支持多達 125 種語言的光學字符識別處理,能有效處理多語言的超市收據。

是否有供開發人員試用的 IronOCR 版本?

是的,IronOCR 提供免費試用版,允許開發人員在購買前探索其功能和性能。

IronOCR 支持哪些平台的收據掃描?

IronOCR 可兼容 .NET 平台,包括 .NET 8、7、6、5 和 Framework 4.6.2 及以上版本,並支持在 Windows、macOS、Azure 和 Linux 環境下運行。

IronOCR 在應用中集成收據掃描功能的特點是什麼?

IronOCR 適合在應用中集成收據掃描功能因其高精度、易用性、跨平台支援及其無縫處理各種輸入格式和語言的能力。

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

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我