在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
發票數據處理指的是接收、管理和驗證來自供應商或賣方的發票,並確保付款正確且及時完成。這涉及設計的步驟,以確保在處理業務交易時的準確性、合規性和效率,從而避免紙質發票。 自動化發票處理可以顯著減少手動數據輸入錯誤並提高效率。 IronOCR 是一個功能強大的光學字符識別(OCR)軟體庫,可以用來從數位檔案中的發票中提取數據或文字,使其成為在 C# 應用程式中自動化發票 OCR 處理的出色工具。
創建一個 Visual Studio 專案。
安裝 IronOCR C# 函式庫。
範例輸入發票圖片。
利用 Tesseract 從收據影像中提取數據。
光學字符識別是一種技術,可識別並轉換各類型的文件、PDF 或文本圖像成為可編輯和可搜索的資料。 OCR技術處理文字的圖像並提取字符,使其可被機器讀取。 先進的OCR發票軟體系統有助於財務管理工具及發票自動化。
好處:OCR透過自動化數據輸入、減少錯誤以及更容易的數據搜索和檢索來提高生產力。 它還支持文件存檔,幫助企業管理無紙化工作流程。
OCR 技術已經顯著發展,使其在處理文件和發票數據提取方面變得高效且具有高度準確性,能夠適應各種不同的發票格式,從而減少手動數據輸入、消除手動發票處理,並提升數據安全性。
IronOCR 是一個強大的光學字符識別(OCR)庫,適用於 .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(光學字符辨識)從圖像(例如,發票)中提取文本。 以下是每個代碼部分的說明,而不包括實際代碼:
許可證密鑰設定:
該程式碼首先設置IronOCR的授權金鑰。 此金鑰是使用該函式庫全部功能所需的。 如果您有有效的授權,請將「Your License」替換為您的實際授權金鑰。
指定輸入檔案:
filePath 變數保存包含發票圖像的位置(在此情況下為 "sample1.jpg")。 這是將進行文字提取的文件。
建立一個 OCR 實例:
創建了一個 IronTesseract 的實例。 IronTesseract 是負責對輸入資料(影像或 PDF)執行 OCR 操作的類別。
載入影像:
然後,程式碼創建了一個 OcrInput 物件,用於載入圖像(在此情況下,由 filePath 指定的 JPG 檔案)。 LoadImage 方法用於讀取圖像文件並準備進行 OCR。
應用圖像濾鏡:
此程式碼包含一個過濾步驟,並可選擇應用一些圖像處理方法,例如校正影像傾斜的 Deskew 和去除影像噪音的 DeNoise,以提高 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 文件)包含要從中提取文字的文檔或內容。 該路徑可以指向本地系統或其他可訪問存儲中的圖像文件。
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 任務,包括收據掃描、文件轉換和數據輸入自動化。