C# 和 .NET 中的波斯語 OCR

This article was translated from English: Does it need improvement?
Translated
View the article in English
Other versions of this document:

在波斯語中 新增 125 種 OCR 語言

IronOCR 是一個 C# 軟體元件,允許 .NET 程式設計師從圖像和 PDF 文件中讀取 126 種語言(包括波斯語)的文字。

它是 Tesseract 的一個高級分支,專為 .NET 開發人員構建,在速度和準確性方面通常優於其他 Tesseract 引擎。

IronOcr.Languages.波斯語的內容

此軟體包包含 46 種適用於 .NET 的 OCR 語言:

  • 波斯語
  • 波斯語最佳
  • PersianFast

下載

波斯語語言包[波斯語]

安裝

我們首先需要做的就是將我們的波斯語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
$vbLabelText   $csharpLabel

上面的程式碼範例示範如何使用 IronOCR 函式庫對波斯語影像執行 OCR 操作。 必須安裝波斯語語言包,並且必須正確指定圖像路徑。 OCR 操作在using語句中執行,以確保資源正確釋放。