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 语句中执行的,以确保正确处置资源。