發票 OCR 機器學習(逐步教學)
在當今快速變遷的商業環境中,自動化工作任務和非結構化資料已成為提高效率和減少手動錯誤的關鍵策略。 其中一個任務是從發票或採購訂單中提取資訊,這一過程傳統上需要大量手動努力。 然而,得益於機器學習、深度學習模型和光學字元識別(OCR)軟體技術的進步,企業現在可使用IronOCR等工具來簡化該發票資訊提取過程。 在本文中,我們將探索如何利用機器學習和IronOCR來改變發票處理的方式。
了解發票OCR工具
OCR技術已經存在一段時間,但隨著機器學習的出現,其在發票處理和資料提取上的應用有了顯著提升。 OCR,全稱為光學字元識別,是一種將各類文件,例如含有發票資訊的掃描紙質文件、PDF文件、財務文件或數位相機拍攝的輸入圖像,轉換為可編輯和搜索資料的技術。 它實質上是通過圖像預處理將圖像中的文字轉換為機器可讀的文字。
IronOCR是一個建立在機器學習演算法之上的強大OCR程式庫,可以整合到各類應用和程式語言中,使其成為處理發票的多功能工具。 通過使用IronOCR,企業可以自動化發票資料提取,例如發票號碼、日期、供應商詳情和項目明細,準確性驚人。
使用IronOCR進行發票OCR的好處
使用IronOCR進行發票處理提供了許多好處,可以顯著提高您組織的財務操作效率和準確性,例如應付帳款。 讓我們更詳細地探討這些好處:
1. 準確性和減少錯誤
IronOCR採用先進的機器學習演算法來準確識別和提取發票上的文字。 這將降低資料輸入的人為錯誤風險,確保關鍵財務資訊準確記錄。
2. 時間和成本節省
自動化IronOCR的發票處理顯著減少了手動資料輸入所需的時間和資源。 這可以通過優化員工時間和減少手工勞動需求來節省大量成本。
3. 提高效率
IronOCR可以快速高效地處理大量發票。 它取消了員工從每張發票手動輸入資料的需求,使他們能專注於更具策略性的任務。
4. 可擴展性
IronOCR具有擴展性,可以在您的業務擴展時處理不斷增長的發票數量。 您不需要擔心增加的工作負載和邊緣框會淹沒您的發票文件處理系統。
5. 全球影響力
IronOCR支持超過125種語言,使企業能夠處理來自世界各地供應商和客戶的發票。 無論發票以哪種語言編寫,IronOCR都可以準確提取資料。
6. 多格式支持
IronOCR可以處理各種格式的發票,包括掃描圖像、基於圖像的PDF和基於文字的PDF。 這種多功能性確保您可以輕鬆處理來自不同來源和格式的發票。
7. 自定義和資料提取
您可以自定義IronOCR以從發票中提取特定的資料字段,例如發票號碼、日期、供應商詳情和項目明細資訊。 這種自定義級別使您可以根據您的具體業務需求定制解決方案。
8. 合規性和審計追溯
使用IronOCR的自動發票處理有助於保持準確記錄並提供審計追溯。 這對於遵循財務法規和簡化審計過程至關重要。
9. 減少發票處理週期
IronOCR流線和自動化的本質縮短了處理發票的時間,從而縮短了發票處理週期。 這可以加快對供應商的付款速度並改善關係。
10. 增強的資料分析
通過將發票資料置於結構化的數位格式中,您可以進行更深入的資料分析。 這可以幫助識別趨勢、優化開支以及做出明智的財務決策。
執行IronOCR以進行發票處理
若要執行IronOCR進行發票處理,請遵循以下一般步驟:
Step 1: Create a New C
首先,在您偏愛的開發環境(例如Visual Studio或Visual Studio Code)中建立一個新的C#專案或打開現有專案。 我正在使用Visual Studio 2022 IDE和控制台應用程式來進行此演示。 您可以在任何專案型別中使用相同的實施,例如ASP.NET Web API、ASP.NET MVC、ASP.NET Web Forms或任何.NET Framework。

步驟2:通過NuGet包管理器安裝IronOCR
若要在您的專案中使用IronOCR,您需要安裝IronOCR NuGet包。 以下是操作方法:
-
打開NuGet包管理器控制台。 在Visual Studio中,您可以在"工具" > "NuGet包管理器" > "包管理器控制台"下找到這一選項。

-
執行以下命令來安裝IronOCR包:
Install-Package IronOcr

- 等待包完成安裝。 安裝完成後,您可以在您的專案中開始使用IronOCR。
Step 3: Implement OCR in Your C
現在,讓我們編寫C#程式碼以使用IronOCR對發票執行OCR。 我們將在此範例中使用以下樣本發票。

以下樣本程式碼會將發票圖像作為輸入,並從發票中提取資料,例如發票號碼、採購訂單等。
// Define the path to the invoice image
string invoicePath = @"D:\Invoices\SampleInvoice.png";
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Add the invoice image to the OCR input
input.AddImage(invoicePath);
// Perform OCR on the input image and store result
OcrResult result = ocr.Read(input);
// Output the extracted text from the image to the console
Console.WriteLine(result.Text);
}
// Define the path to the invoice image
string invoicePath = @"D:\Invoices\SampleInvoice.png";
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Add the invoice image to the OCR input
input.AddImage(invoicePath);
// Perform OCR on the input image and store result
OcrResult result = ocr.Read(input);
// Output the extracted text from the image to the console
Console.WriteLine(result.Text);
}
' Define the path to the invoice image
Dim invoicePath As String = "D:\Invoices\SampleInvoice.png"
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Add the invoice image to the OCR input
input.AddImage(invoicePath)
' Perform OCR on the input image and store result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from the image to the console
Console.WriteLine(result.Text)
End Using
上述程式碼是一個精簡的C#範例,它使用IronOCR對單一發票圖像(SampleInvoice.png)進行OCR,然後將提取的發票資料列印到控制台上。 請確保將invoicePath變數替換為您的具體發票圖像文件的路徑。

讓我們一次性輸入多張發票並提取它們的資料。 以下是我們用作輸入的發票目錄。

以下樣本程式碼將同時從多個發票中提取文字。
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all images to the console
Console.WriteLine(result.Text);
}
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all images to the console
Console.WriteLine(result.Text);
}
' Get all PNG files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.png")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddImage(file)
Next file
' Perform OCR on all the added images and store the result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from all images to the console
Console.WriteLine(result.Text)
End Using
上述程式碼將從文件夾中獲得所有PNG圖像,提取資料,然後在控制台列印文件夾中所有發票的提取資料。

將提取的資料保存為可搜索的PDF發票
以下程式碼將從文件夾中讀取所有圖像,執行資料提取,並將它們保存為單一可搜索的PDF發票。
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Save the result as a searchable PDF
result.SaveAsSearchablePdf(@"D:\Invoices\Searchable.pdf");
}
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Save the result as a searchable PDF
result.SaveAsSearchablePdf(@"D:\Invoices\Searchable.pdf");
}
' Get all PNG files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.png")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddImage(file)
Next file
' Perform OCR on all the added images and store the result
Dim result As OcrResult = ocr.Read(input)
' Save the result as a searchable PDF
result.SaveAsSearchablePdf("D:\Invoices\Searchable.pdf")
End Using
程式碼在所有範例中幾乎相似; 我們只是做了些許改變以展示不同的使用案例。 以下顯示的就是輸出的PDF:

這樣,IronPDF提供了自動化發票處理和文件處理的最簡單方式。
從PDF發票中提取發票資料
若要使用IronOCR從PDF發票中提取資料,您可以採用類似於前面程式碼範例的方法。 IronOCR能夠處理基於圖像和基於文字的PDF。 這是一個如何從PDF發票中提取資料的簡要範例:
// Get all PDF files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.pdf");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddPdf(file);
}
// Perform OCR on all the added PDFs and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text);
}
// Get all PDF files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.pdf");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddPdf(file);
}
// Perform OCR on all the added PDFs and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text);
}
' Get all PDF files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.pdf")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddPdf(file)
Next file
' Perform OCR on all the added PDFs and store the result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text)
End Using
上述程式碼使用IronOCR有效地批量處理目錄(@"D:\Invoices\")中的多個PDF發票。 它檢索文件路徑,將每個PDF新增進行OCR處理,結合提取的文字,並將結果列印到控制台上。 此方法簡化了處理大量發票的組織的發票資料提取過程,提高效率並減少手動工作。

結論
總之,機器學習和先進的OCR技術如IronOCR的融合正在重新定義發票處理的方式。 本文為您講解了使用IronOCR的過程,展示了其顯著的優勢。 通過採用IronOCR,企業可以實現更高的準確性、節省時間和金錢,並輕鬆應對各種格式和語言的發票。 消除手動資料輸入不僅提升了效率,還降低了財務交易中代價高昂的錯誤可能性。 IronOCR簡化並提升發票處理工作流程,使其成為希望提高財務操作的企業在當今競爭環境中的明智選擇。 此外,IronOCR提供了一套強大的功能,包括支持超過125種語言、自定義資料提取、以及與基於圖像和基於文字的PDF的相容性。
儘管IronOCR的功能集令人印象深刻,同時值得注意的是IronOCR的定價模型設計滿足各類商業需求,為小型企業和大型公司提供靈活的選項和免費試用。 無論您是在處理幾個發票還是在管理大量的財務文件,IronOCR都是一個值得信賴且具性價比的解決方案。




