Persian OCR in C# and .NET
本文件的其他版本:
IronOCR 是一款 C# 軟體元件,讓 .NET 開發人員能夠從 126 種語言(包括波斯語)的圖片和 PDF 文件中讀取文字。
這是 Tesseract 的進階分支版本,專為 .NET 開發者打造,無論在速度或準確度方面,其表現均經常優於其他 Tesseract 引擎。
IronOcr.Languages.Persian 的內容
此套件包含 46 種適用於 .NET 的 OCR 語言:
- 波斯語
- 波斯語Best
- 波斯語Fast
下載
波斯語語言套件 [فارسی]
安裝
我們首先必須將波斯語 OCR 套件安裝至您的 .NET 專案中。
PM> Install-Package IronOcr.Languages.Persian
程式碼範例
此 C# 程式碼範例用於從圖片或 PDF 文件中讀取波斯文內容。
// Install IronOcr.Languages.Persian package using NuGet Package Manager
// PM> Install-Package IronOcr.Languages.Persian
using IronOcr;
class Program
{
static void Main()
{
// Create a new instance of IronTesseract
var Ocr = new IronTesseract();
// Set the language to Persian
Ocr.Language = OcrLanguage.Persian;
// Load input image or PDF file
using (var Input = new OcrInput(@"images\Persian.png"))
{
// Perform OCR to read text from the image
var Result = Ocr.Read(Input);
// Extract the recognized text
var AllText = Result.Text;
// Display the extracted text
Console.WriteLine(AllText);
}
}
}
// Install IronOcr.Languages.Persian package using NuGet Package Manager
// PM> Install-Package IronOcr.Languages.Persian
using IronOcr;
class Program
{
static void Main()
{
// Create a new instance of IronTesseract
var Ocr = new IronTesseract();
// Set the language to Persian
Ocr.Language = OcrLanguage.Persian;
// Load input image or PDF file
using (var Input = new OcrInput(@"images\Persian.png"))
{
// Perform OCR to read text from the image
var Result = Ocr.Read(Input);
// Extract the recognized text
var AllText = Result.Text;
// Display the extracted text
Console.WriteLine(AllText);
}
}
}
' Install IronOcr.Languages.Persian package using NuGet Package Manager
' PM> Install-Package IronOcr.Languages.Persian
Imports IronOcr
Friend Class Program
Shared Sub Main()
' Create a new instance of IronTesseract
Dim Ocr = New IronTesseract()
' Set the language to Persian
Ocr.Language = OcrLanguage.Persian
' Load input image or PDF file
Using Input = New OcrInput("images\Persian.png")
' Perform OCR to read text from the image
Dim Result = Ocr.Read(Input)
' Extract the recognized text
Dim AllText = Result.Text
' Display the extracted text
Console.WriteLine(AllText)
End Using
End Sub
End Class
上述程式碼範例示範了如何利用 IronOCR程式庫對波斯語圖片執行 OCR 處理。 必須安裝波斯語語言套件,且圖片路徑應正確指定。 OCR 操作是在 using 語句中執行的,以確保資源能被妥善釋放。

