使用機器學習軟體從圖像中提取文字
利用機器學習從捕獲或掃描的文件中的文字圖像提取文字是在計算機視覺和自然語言處理交匯處的一個迅速增長的領域。 這項技術利用高級機器學習、物體識別算法、高級圖形軟體、深層和深暗網路,以及神經網路架構,準確識別和提取圖像和掃描紙質文件中的文字資訊。 通過使用各種機器學習技術如光學字元識別 (OCR) 和深度學習,它能夠將視覺場景文字檢測自動而高效地轉換為可編輯和可搜索的結構化資料,並進行物體檢測。
在這個不斷變化的環境中,研究人員和從業者不斷努力提高準確性、速度和多功能性,使文字檢測和提取從圖像、機器可讀資料和掃描的文件中成為應用程式的重要組成部分,如印刷文件數字化、內容索引、翻譯和可及性增強。
在本文中,我們將討論如何使用IronOCR這個由強大的機器學習算法和文字相關功能驅動的OCR程式庫從圖像中提取文字。 文字提取,也稱為關鍵字提取,是基於機器學習自動掃描和提取相關或基本詞彙和短語,來自非結構化資料或公司的中央資料庫。
如何使用機器學習從圖像中提取文字?
- 下載C#圖書館以從圖像中提取文字。
- 建立場景文字識別的OcrInput物件來載入特定圖像。
- 使用ocrTesseract.Read方法從圖像中提取資料。
- 使用Console.WriteLine方法在控制台中列印提取的文字。
- 使用CropRectangle物件對圖像的某個區域進行OCR。
IronOCR - 一個光學字元識別 (OCR) 程式庫
IronOCR是一個傑出而先進的光學字元識別 (OCR) 軟體,在從圖像和文件中提取文字的技術中處於最前沿。 由Iron Software開發,這個強大的OCR引擎被設計用於準確且高效地將掃描圖像、PDF,甚至是文字的照片轉換為可編輯和可搜索的數字內容。 憑藉其對機器學習算法和神經網路的熟練運用,IronOCR為各種應用提供了一個強大的解決方案,包括需要精確文字識別的資料提取、內容索引和自動化過程。
它能夠處理多種語言和不同字體,使其成為開發人員和企業尋求其軟體和應用中精簡文字識別算法提取功能的一個多功能工具。 您可以使用IronOCR自動掃描文字,使用將非結構化資料轉換為完美掃描頁面的常用文字識別技術,使用文字提取算法。
安裝IronOCR
IronOCR可以使用NuGet包管理器安裝。 以下是安裝IronOCR的步驟:
- 首先,建立一個新的C# Visual Studio項目或打開一個已存在的項目。

- 一旦項目建立好,轉到頂部選單中的工具並選擇NuGet包管理器,然後選擇解決方案的NuGet包管理器。

- 螢幕上將出現一個新窗口。 轉到瀏覽選項卡並在搜索欄中輸入IronOCR。
- 會出現一個IronOCR包的列表。 選擇最新的一個並點擊安裝。

- 根據您的網際網路情況需要幾秒鐘; 之後,IronOCR在您的C#項目中可以使用。
從圖像到可編輯和可搜索資料的文字檢測
使用IronOCR,您可以輕鬆使用圖像處理技術和機器學習來提取文字。 在本節中,我們將討論如何使用IronOCR從圖像中提取文字。
using IronOcr;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the image path and perform OCR on the image
using (var ocrInput = new OcrInput(@"images\image.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}using IronOcr;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the image path and perform OCR on the image
using (var ocrInput = new OcrInput(@"images\image.png"))
{
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}Imports IronOcr
Imports System
' Create a new instance of the IronTesseract class
Private ocrTesseract = New IronTesseract()
' Specify the image path and perform OCR on the image
Using ocrInput As New OcrInput("images\image.png")
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text to the console
Console.WriteLine(ocrResult.Text)
End Using這段C#程式碼展示了IronOCR這個光學字元識別 (OCR) 圖書館的使用方法。 以下是逐步說明:
導入程式庫:
using IronOcr; using System;using IronOcr; using System;Imports IronOcr Imports System$vbLabelText $csharpLabel程式碼以導入必要程式庫開頭,包括提供OCR功能的IronOCR和提供一般功能的System命名空間。
初始化IronTesseract並載入圖像:
var ocrTesseract = new IronTesseract();var ocrTesseract = new IronTesseract();Dim ocrTesseract As New IronTesseract()$vbLabelText $csharpLabel這段程式碼建立一個由IronOCR提供的OCR引擎IronTesseract的實例。
using (var ocrInput = new OcrInput(@"images\image.png"))using (var ocrInput = new OcrInput(@"images\image.png"))Using ocrInput As New OcrInput("images\image.png")$vbLabelText $csharpLabel用於處理的圖像的路徑實例化OcrInput物件。 在這個例子中,圖像文件在"images"目錄中名為"image.png"。
進行OCR並提取文字:
var ocrResult = ocrTesseract.Read(ocrInput);var ocrResult = ocrTesseract.Read(ocrInput);Dim ocrResult = ocrTesseract.Read(ocrInput)$vbLabelText $csharpLabel這行程式碼調用IronTesseract實例的Read方法,傳入OcrInput物件。 此方法對提供的圖像執行OCR並提取文字。
顯示提取的文字:
Console.WriteLine(ocrResult.Text);Console.WriteLine(ocrResult.Text);Console.WriteLine(ocrResult.Text)$vbLabelText $csharpLabel最後,提取的文字使用Console.WriteLine列印到控制台,顯示從圖像獲得的OCR結果。
這段程式碼片段使用IronOCR對指定圖像的文字識別進行OCR,並將提取的文字輸出到控制台。
輸入圖像

輸出

對圖像上指定區域進行OCR
您也可以使用IronOCR對圖像上的特定區域進行OCR。 這是程式碼範例:
using IronOcr;
using IronSoftware.Drawing;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the region on the image to be processed
using (var ocrInput = new OcrInput())
{
var ContentArea = new CropRectangle(x: 20, y: 20, width: 400, height: 50);
// Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea);
// Perform OCR on the specified region and extract text
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}using IronOcr;
using IronSoftware.Drawing;
using System;
// Create a new instance of the IronTesseract class
var ocrTesseract = new IronTesseract();
// Specify the region on the image to be processed
using (var ocrInput = new OcrInput())
{
var ContentArea = new CropRectangle(x: 20, y: 20, width: 400, height: 50);
// Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea);
// Perform OCR on the specified region and extract text
var ocrResult = ocrTesseract.Read(ocrInput);
// Print the extracted text to the console
Console.WriteLine(ocrResult.Text);
}Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Create a new instance of the IronTesseract class
Private ocrTesseract = New IronTesseract()
' Specify the region on the image to be processed
Using ocrInput As New OcrInput()
Dim ContentArea = New CropRectangle(x:= 20, y:= 20, width:= 400, height:= 50)
' Add the image with the defined content area
ocrInput.AddImage("r3.png", ContentArea)
' Perform OCR on the specified region and extract text
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Print the extracted text to the console
Console.WriteLine(ocrResult.Text)
End Using這段C#程式碼利用IronOCR圖書館進行光學字元識別 (OCR)。 它首先導入必要的程式庫,包括IronOCR和System。 建立了一個OCR引擎IronTesseract的實例。 程式碼設置了圖像中要進行處理的特定ContentArea,使用CropRectangle,專注於一個定義的區域。 位於這個指定區域內的圖像("r3.png")然後被新增進行OCR處理。 OCR引擎閱讀了指定的內容區域,提取出文字,並使用Console.WriteLine將結果文字列印到控制台。
輸出

結論
通過機器學習從圖像中提取文字,特別是使用像IronOCR這樣的光學字元識別 (OCR) 程式庫,標誌著在計算機視覺和自然語言處理交匯處的變革性進步。 光學字元識別 (OCR) 技術和深度學習技術在有效地將視覺文字轉換為可編輯和可搜索資料方面起著關鍵作用,用於文件數字化、內容索引和可及性增強等重要用途。
作為一個傑出的OCR圖書館,IronOCR展現了這種融合的潛力,在跨多種語言和字體風格的掃描圖像和PDF中精確地轉換成數字、可編輯內容方面表現出色。 它無縫整合到像C#這樣的程式設計語言中,實現流線化的實施,進一步放大了在眾多應用和領域中從圖像中提取文字的變革性影響。
若想了解更多有關IronOCR和所有相關功能,請存取此連結。 從圖像中提取文字的完整教學可通過以下連結獲得。 IronOCR授權可以從這個連結購買。
