在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
IronOCR 是一個 OCR 函式庫,可以用於從圖像中識別文字資料以進行資訊提取,包括收據 OCR。 它建立在 Tesseract OCR 引擎之上,被認為是截至目前可用於收據識別的最準確的 OCR 引擎之一。 IronOCR 可用於從不同類型的文件(包括 PNG、JPG、TIFF、JSON 格式和 PDF)中讀取關鍵信息的文本,並能識別多種語言的文本。
IronOCR 的一個主要功能或服務是能夠自動檢測文字方向,即使圖像已被旋轉或扭曲,這也使其對於收據 OCR 特別有用。 這對於收據上傳的準確文字識別和數據提取至關重要,因為收據通常有大量信息且可能被折疊或皺褶,導致文字偏斜。
開啟 Visual Studio 軟體並進入檔案選單。 選擇「新專案」,然後選擇「主控台應用程式」。
在相應的文字框中輸入專案名稱並選擇路徑。 然後,點擊建立按鈕。 選擇所需的 .NET Framework,如下圖所示:
在 Visual Studio 中創建新專案
Visual Studio 專案現在將生成控制台應用程式的結構。 完成後,它將打開 Program.cs 文件,您可以在其中編寫和執行源代碼。
從 Visual Studio 新專案精靈生成的 program.cs 檔案
在 Visual Studio 中,您可以輕鬆地將 IronOCR 整合到您的 C# 專案中。 IronOCR 提供多種方式與 C# .NET 專案整合。 在這裡,我們將討論其中之一:使用 NuGet Package Manager 安裝 IronOCR。
在 Visual Studio 中,前往工具 > NuGet 套件管理員 > 套件管理員主控台
Visual Studio NuGet 套件管理控制台
點擊後,Visual Studio 視窗底部會出現一個新的控制台。 在控制台中輸入以下命令並按下 Enter 鍵。
Install-Package IronOcr
IronOCR只需幾秒鐘即可安裝完成。
IronOCR 是一個功能強大的光學字符識別庫,可以用來從收據中提取和獲取數據詳細資訊。使用 IronOCR,您可以拍攝收據的照片,並將其轉換為機器可讀文本,便於分析和處理,同時不會損害數據隱私。
以下是如何使用 IronOCR 從收據中提取文本的示例,並展示收據 OCR 的工作原理。
using IronOcr;
using System;
IronTesseract ocrTesseract = new IronTesseract();
using (OcrInput ocrInput = new OcrInput("ocr.png"))
{
OcrResult ocrResult = ocrTesseract.Read(ocrInput);
string RecognizedText = ocrResult.Text;
Console.WriteLine(RecognizedText);
}
using IronOcr;
using System;
IronTesseract ocrTesseract = new IronTesseract();
using (OcrInput ocrInput = new OcrInput("ocr.png"))
{
OcrResult ocrResult = ocrTesseract.Read(ocrInput);
string RecognizedText = ocrResult.Text;
Console.WriteLine(RecognizedText);
}
Imports IronOcr
Imports System
Private ocrTesseract As New IronTesseract()
Using ocrInput As New OcrInput("ocr.png")
Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput)
Dim RecognizedText As String = ocrResult.Text
Console.WriteLine(RecognizedText)
End Using
請參閱從影像中讀取文字的教學,以獲取有關IronOCR如何使用C#程式語言從影像中讀取文字的詳細資訊。
上述程式碼的輸出如下:
- LOGO SHOP
- LOREM IPSUM
- DOLOR SITAMET CONSECTETUR
- ADIPISCING ELIT
- 1 LOREM IPSUM $3.20
- 2 ORNARE MALESUADA $9.50
- 3 PORTA FERMENTUM $5.90
- 4 SODALES ARCU $6.00
- 5 ELEIFEND $9.00
- 6 SEMNISIMASSA $0.50
- 7 DUIS FAMES DIS $7.60
- 8 FACILISIRISUS $810
- TOTAL AMOUNT $49.80
- CASH $50.00
作為一個強大的OCR庫,IronOCR允許開發者從掃描的收據中提取重要信息,包括稅額和商家名稱。
以下是範例,說明您如何使用IronOCR從收據圖像中提取總金額:
using IronOcr;
using System;
IronTesseract ocrTesseract = new IronTesseract();
ocrTesseract.Language = OcrLanguage.English;
// Code line to load the receipt image
using (OcrInput ocrInput = new OcrInput("ocr.png"))
{
// Optimize the input image for OCR
ocrInput.DeNoise(true);
ocrInput.Contrast();
ocrInput.EnhanceResolution();
ocrInput.ToGrayScale();
OcrResult ocrResult = ocrTesseract.Read(ocrInput);
// Search for the total price in the OCR result
var totalPrice = ocrResult.Text.Contains("Total:") ? ocrResult.Text.Split("Total:")[1].Split("\n")[0] : "";
Console.WriteLine("Total Price: " + totalPrice);
}
using IronOcr;
using System;
IronTesseract ocrTesseract = new IronTesseract();
ocrTesseract.Language = OcrLanguage.English;
// Code line to load the receipt image
using (OcrInput ocrInput = new OcrInput("ocr.png"))
{
// Optimize the input image for OCR
ocrInput.DeNoise(true);
ocrInput.Contrast();
ocrInput.EnhanceResolution();
ocrInput.ToGrayScale();
OcrResult ocrResult = ocrTesseract.Read(ocrInput);
// Search for the total price in the OCR result
var totalPrice = ocrResult.Text.Contains("Total:") ? ocrResult.Text.Split("Total:")[1].Split("\n")[0] : "";
Console.WriteLine("Total Price: " + totalPrice);
}
Imports Microsoft.VisualBasic
Imports IronOcr
Imports System
Private ocrTesseract As New IronTesseract()
ocrTesseract.Language = OcrLanguage.English
' Code line to load the receipt image
Using ocrInput As New OcrInput("ocr.png")
' Optimize the input image for OCR
ocrInput.DeNoise(True)
ocrInput.Contrast()
ocrInput.EnhanceResolution()
ocrInput.ToGrayScale()
Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput)
' Search for the total price in the OCR result
Dim totalPrice = If(ocrResult.Text.Contains("Total:"), ocrResult.Text.Split("Total:")(1).Split(vbLf)(0), "")
Console.WriteLine("Total Price: " & totalPrice)
End Using
由於OcrInput
類別提供的多重設置,可以優化輸入圖像,以提高OCR過程的準確性。
用於演示從收據中提取特定數據的輸入圖像
- Total 16.5
IronOCR 可用於讀取收據上的條碼以及文字。 要使用 IronOCR 读取收据上的条形码,您需要结合使用 BarcodeReader
类和 ReadBarCodes
方法。
以下是一個示例,說明如何使用IronOCR讀取收據圖像上的條碼。
using IronOcr;
using System;
var ocrTesseract = new IronTesseract();
ocrTesseract.Configuration.ReadBarCodes = true;
using (var ocrInput = new OcrInput("b.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
foreach (var barcode in ocrResult.Barcodes)
{
Console.WriteLine(barcode.Value);
}
}
using IronOcr;
using System;
var ocrTesseract = new IronTesseract();
ocrTesseract.Configuration.ReadBarCodes = true;
using (var ocrInput = new OcrInput("b.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
foreach (var barcode in ocrResult.Barcodes)
{
Console.WriteLine(barcode.Value);
}
}
Imports IronOcr
Imports System
Private ocrTesseract = New IronTesseract()
ocrTesseract.Configuration.ReadBarCodes = True
Using ocrInput As New OcrInput("b.png")
Dim ocrResult = ocrTesseract.Read(ocrInput)
For Each barcode In ocrResult.Barcodes
Console.WriteLine(barcode.Value)
Next barcode
End Using
讀取條碼的輸入
處理條碼圖片的結果
上面的文章解釋了在 C# 專案中安裝和使用 IronOCR 從收據中提取資料的過程,並提供了示例代碼片段。
請閱讀從圖像讀取文字的教程。
IronOCR 是 Iron Suite 的一部分,其中包含五個不同的 .NET 庫,用於操作文件和圖像。 您可以以兩份IronOCR 授權的價格購買整個 Iron Suite。
在您的生產應用中嘗試使用 IronOCR,免費試用。