在實際環境中測試
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
發票數據處理指的是接收、管理和驗證來自供應商或賣方的發票,並確保付款正確且及時完成。這涉及設計的步驟,以確保在處理業務交易時的準確性、合規性和效率,從而避免紙質發票。 自動化發票處理可以顯著減少手動數據輸入錯誤並提高效率。 IronOCR是一個強大的光學字元識別(光學字符識別)可用於從數位文件中提取發票數據或文字的軟體庫,是在 C# 應用中自動化發票 OCR 處理的優秀工具。
創建一個 Visual Studio 專案。
安裝 IronOCR C# 函式庫。
範例輸入發票圖片。
利用 Tesseract 從收據影像中提取數據。
光學文字識別是一項技術,可以識別和轉換各種類型的文件、PDF 檔或文字圖像為可編輯和可搜尋的數據。 OCR技術處理文字的圖像並提取字符,使其可被機器讀取。 先進的OCR發票軟體系統有助於財務管理工具及發票自動化。
好處:OCR 通過自動化數據輸入、減少錯誤以及使數據搜索和檢索更輕鬆來提高生產力。 它還支持文件存檔,幫助企業管理無紙化工作流程。
OCR 技術已經顯著發展,使其在處理文件和發票數據提取方面變得高效且具有高度準確性,能夠適應各種不同的發票格式,從而減少手動數據輸入、消除手動發票處理,並提升數據安全性。
IronOCR 是一款功能強大的光學字符識別工具(光學字符識別).NET 的程式庫(C#)讓開發人員能夠從圖像、PDF 和其他文檔格式中提取文本、開發 OCR 發票軟體,以及實現應付賬款工作流程。 它提供了一個易於使用的 API,用於將 OCR 功能整合到應付賬款系統或會計系統中。
在開始之前,請確保您擁有以下內容:
開啟 Visual Studio 並點擊「建立新專案」。
在選項中選擇控制台應用程式。
提供專案名稱和路徑。
選擇 .NET 版本類型。
在 Visual Studio 的專案中,前往工具 > NuGet 套件管理員 > 管理方案的 NuGet 套件。 點擊「瀏覽」標籤,然後搜尋 IronOCR。 選擇 IronOCR 並點擊安裝。
另一個選項是使用控制台和以下命令。
dotnet add package IronOcr --version 2024.12.2
dotnet add package IronOcr --version 2024.12.2
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet add package IronOcr --version 2024.12.2
包含發票號碼的數位發票樣本圖片。
現在使用以下代碼來從發票中提取資料以進行OCR發票處理。
using IronOcr;
License.LicenseKey = "Your License";
string filePath = "sample1.jpg"; // image for invoice OCR
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(filePath);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
// next steps are to process data and use the extracted and validated data with invoice date
}
using IronOcr;
License.LicenseKey = "Your License";
string filePath = "sample1.jpg"; // image for invoice OCR
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(filePath);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
// next steps are to process data and use the extracted and validated data with invoice date
}
Imports IronOcr
License.LicenseKey = "Your License"
Dim filePath As String = "sample1.jpg" ' image for invoice OCR
' Create an instance of IronTesseract
Dim ocr = New IronTesseract()
' Load the image or PDF file
Using ocrInput As New OcrInput()
ocrInput.LoadImage(filePath)
' Optionally apply filters if needed
ocrInput.Deskew()
' ocrInput.DeNoise();
' Read the text from the image or PDF
Dim ocrResult = ocr.Read(ocrInput)
' Output the extracted text
Console.WriteLine("Extracted Text:")
Console.WriteLine(ocrResult.Text)
' next steps are to process data and use the extracted and validated data with invoice date
End Using
以下代碼說明如何在 C# 中使用 IronOCR 庫從圖像中提取文字(例如,發票)使用OCR(光學字符識別). 以下是每個代碼部分的說明,而不包括實際代碼:
License Key Setup(許可證金鑰設置):
該程式碼首先設置IronOCR的授權金鑰。 此金鑰是使用該函式庫全部功能所需的。 如果您有有效的授權,請將「Your License」替換為您的實際授權金鑰。
指定輸入文件:
filePath
變數保存包含發票圖片的位置。(在這種情況下,“sample1.jpg”). 這是將進行文字提取的文件。
創建 OCR 實例:
創建了一個 IronTesseract 的實例。 IronTesseract 是負責對輸入數據執行 OCR 操作的類別。(圖像或 PDF).
載入影像:
然後,程式碼建立一個 OcrInput 物件,用於載入圖像。(在這種情況下,由 filePath 指定的 JPG 檔案). LoadImage 方法用於讀取圖像文件並準備進行 OCR。
應用影像濾鏡:
該代碼包含一個過濾步驟,其中可選的圖像處理方法,如傾斜校正(Deskew)(校正偏斜的圖像)和去噪(去除影像噪點),可以應用於提高 OCR 的準確性。 在這種情況下,只有 Deskew 方法是啟用的。
執行OCR:
顯示提取的文字:
為了提高效率,可以只使用圖像的一部分進行提取。
using IronOcr;
using IronSoftware.Drawing;
License.LicenseKey = "Your Key";
string filePath = "sample1.jpg";
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
var ContentArea = new Rectangle(x: 0, y: 0, width: 1000, height: 250);
ocrInput.LoadImage(filePath, ContentArea);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
}
using IronOcr;
using IronSoftware.Drawing;
License.LicenseKey = "Your Key";
string filePath = "sample1.jpg";
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
var ContentArea = new Rectangle(x: 0, y: 0, width: 1000, height: 250);
ocrInput.LoadImage(filePath, ContentArea);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
}
Imports IronOcr
Imports IronSoftware.Drawing
License.LicenseKey = "Your Key"
Dim filePath As String = "sample1.jpg"
' Create an instance of IronTesseract
Dim ocr = New IronTesseract()
' Load the image or PDF file
Using ocrInput As New OcrInput()
Dim ContentArea = New Rectangle(x:= 0, y:= 0, width:= 1000, height:= 250)
ocrInput.LoadImage(filePath, ContentArea)
' Optionally apply filters if needed
ocrInput.Deskew()
' ocrInput.DeNoise();
' Read the text from the image or PDF
Dim ocrResult = ocr.Read(ocrInput)
' Output the extracted text
Console.WriteLine("Extracted Text:")
Console.WriteLine(ocrResult.Text)
End Using
此程式碼使用IronOCR從影像的特定位區域提取文字,並可選擇性地應用如去扭斜等濾鏡以提高準確性。 提取的文本將顯示出來,並準備好進一步使用。
程式碼的第一部分涉及為 IronOCR 設定授權密鑰。 這是使用庫中OCR功能所需的。 您應將授權金鑰替換為從 IronOCR 獲取的實際金鑰,以便訪問該庫的全部功能。
您希望處理的圖像的文件路徑已指定。 這張圖片(在這種情況下,JPG 檔案)包含 OCR 將擷取文字的文件或內容。 該路徑可以指向本地系統或其他可訪問存儲中的圖像文件。
IronTesseract 類別的實例已被創建。 此物件是核心引擎,將在影像上執行光學字符識別。
矩形(感興趣的領域)在圖像內定義。 此矩形指定了OCR引擎將要專注的圖像部分。 在此範例中,矩形從左上角開始(x=0, y=0)寬度為1000像素,高度為250像素。 此步驟可使OCR僅處理圖像中的相關部分,提高準確性和速度。
圖像已加載到 OCR 引擎中,但僅限於已定義的矩形區域。(內容區域)正在處理中。 這讓您可以將 OCR 的範圍縮小到圖像的特定部分,這在圖像包含不相關的區域(如背景或標誌)且您不希望處理時特別有用。
程式碼可選擇性地對圖像應用校正傾斜濾鏡。 Deskewing 是一個將圖像傾斜或旋轉進行校正的過程,以提高光學字符識別(OCR)的準確性。 另一個過濾器denoise可用,但已註釋掉。 如果啟用,它將去除噪點(不需要的標記)從圖像中,這可能進一步提升OCR的準確性。
OCR 引擎讀取圖像(或其指定區域)並提取其識別的任何文本。 結果儲存在一個包含識別文字的物件中。
最後,提取的文字被列印到控制台。 此文本是光學字符辨識 (OCR) 處理的結果,可進一步處理、驗證或用於資料輸入或文件管理等應用中。
IronOCR 需要密鑰才能從發票中提取數據,獲取您的開發者試用密鑰來自授權頁面.
using IronOcr;
License.LicenseKey = "Your Key";
using IronOcr;
License.LicenseKey = "Your Key";
Imports IronOcr
License.LicenseKey = "Your Key"
本文提供了使用 IronOCR 進行發票處理的基本範例。 您可以進一步自訂和擴展此程式碼以符合您的特定需求。
IronOCR 提供高效且易於整合的解決方案,用於從圖像和 PDF 中提取文本,非常適合發票處理。 通過將IronOCR與C#字串操作或正則表達式結合使用,您可以快速處理並提取發票中的重要數據。
這是一個基本的發票處理示例,並且可以進行更高級的配置。(像語言識別、多頁面 PDF 處理等。),您可以微調 OCR 結果,以提高特定用例的準確性。
IronOCR 的 API 非常靈活,除了發票處理外,還可以用於各種 OCR 任務,包括收據掃描、文件轉換和數據輸入自動化。