
已更新 2026年4月21日
Power Automate OCR 開發者教學
這項光學字元識別技術應用於文件數字化、自動化 PDF 資料提取和輸入、發票處理和使掃描的 PDF 可搜尋。
閱讀更多
利用像IronOCR和Tesseract這樣的程式庫,開發者可以存取先進的算法和機器學習技術,從圖像和掃描的文件中提取文字資訊。 本教程將向讀者展示如何使用Tesseract程式庫執行圖像文字提取,然後介紹IronOCR的獨特方法。
使用NuGet套件管理器控制台,輸入以下命令:
或者通過NuGet套件管理器下載套件。
在NuGet套件管理器中安裝Tesseract套件
您必須在安裝NuGet套件後,手動安裝並將語言文件保存到專案資料夾中。 這可以被視為這個特定程式庫的不足。
存取以下網站以下載語言文件。 下載後,解壓縮文件,並將"tessdata"文件夾新增到您的專案的debug資料夾中。
可以使用下面的源程式碼對給定的圖像進行OCR處理:
using Tesseract;
class Program
{
static void Main()
{
// Initialize Tesseract engine with English language data
using var ocrEngine = new TesseractEngine(@"tessdata", "eng", EngineMode.Default);
// Load the image to be processed
using var img = Pix.LoadFromFile("Demo.png");
// Process the image to extract text
using var res = ocrEngine.Process(img);
// Output the recognized text
Console.WriteLine(res.GetText());
Console.ReadKey();
}
}Imports Tesseract
Friend Class Program
Shared Sub Main()
' Initialize Tesseract engine with English language data
Dim ocrEngine = New TesseractEngine("tessdata", "eng", EngineMode.Default)
' Load the image to be processed
Dim img = Pix.LoadFromFile("Demo.png")
' Process the image to extract text
Dim res = ocrEngine.Process(img)
' Output the recognized text
Console.WriteLine(res.GetText())
Console.ReadKey()
End Sub
End ClassTesseractEngine物件,將語言資料載入引擎中。Pix.LoadFromFile載入所需的圖像文件。Process方法提取文字。GetText方法獲得識別的文字並列印到控制台。
從圖像中提取的文字
若要了解更多關於Tesseract與C#的資訊,請存取Tesseract教程。
在NuGet套件管理器控制台中輸入下一條命令:
或者通過NuGet套件管理器安裝IronOCR程式庫,並搭配其他語言額外套件,簡單方便。
通過NuGet套件管理器安裝IronOCR和語言套件
以下是個範例程式碼,用於識別給定圖像中的文字:
using IronOcr;
class Program
{
static void Main()
{
// Create an IronTesseract instance with predefined settings
var ocr = new IronTesseract()
{
Language = OcrLanguage.EnglishBest,
Configuration = { TesseractVersion = TesseractVersion.Tesseract5 }
};
// Create an OcrInput instance for image processing
using var input = new OcrInput();
// Load the image to be processed
input.AddImage("Demo.png");
// Process the image and extract text
var result = ocr.Read(input);
// Output the recognized text
Console.WriteLine(result.Text);
Console.ReadKey();
}
}Imports IronOcr
Friend Class Program
Shared Sub Main()
' Create an IronTesseract instance with predefined settings
Dim ocr = New IronTesseract() With {
.Language = OcrLanguage.EnglishBest,
.Configuration = { TesseractVersion = TesseractVersion.Tesseract5 }
}
' Create an OcrInput instance for image processing
Dim input = New OcrInput()
' Load the image to be processed
input.AddImage("Demo.png")
' Process the image and extract text
Dim result = ocr.Read(input)
' Output the recognized text
Console.WriteLine(result.Text)
Console.ReadKey()
End Sub
End ClassIronTesseract物件,設置語言和Tesseract版本。AddImage方法載入圖像文件。Read方法處理圖像並提取文字,然後將其列印到控制台。
使用IronOCR程式庫提取的文字輸出
如需詳細的IronOCR教程,請參考本文章以從C#中的圖像中讀取文字。