使用 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.Bengali 的内容

此软件包包含 114 种适用于 .NET 的 OCR 语言:

  • 孟加拉语
  • BengaliBest
  • BengaliFast
  • 孟加拉字母
  • BengalaliAlphabetBest
  • 孟加拉语字母快速

下载

孟加拉语语言包[Bangla]

安装

我们首先需要做的就是将我们的孟加拉语OCR 包安装到您的 .NET 项目中。

Install-Package IronOCR.Languages.Bengali

代码示例

这段 C# 代码示例从图像或 PDF 文档中读取孟加拉语文本。

// Import the IronOcr namespace
using IronOcr;

class BengaliOcrExample
{
    static void Main()
    {
        // Create an instance of IronTesseract
        var Ocr = new IronTesseract();

        // Specify the language for OCR
        Ocr.Language = OcrLanguage.Bengali;

        // Process the image and extract text
        using (var Input = new OcrInput(@"images\Bengali.png"))
        {
            // Perform OCR on the input image
            var Result = Ocr.Read(Input);

            // Get the extracted text
            var AllText = Result.Text;

            // Output the extracted text to the console
            System.Console.WriteLine(AllText);
        }
    }
}
// Import the IronOcr namespace
using IronOcr;

class BengaliOcrExample
{
    static void Main()
    {
        // Create an instance of IronTesseract
        var Ocr = new IronTesseract();

        // Specify the language for OCR
        Ocr.Language = OcrLanguage.Bengali;

        // Process the image and extract text
        using (var Input = new OcrInput(@"images\Bengali.png"))
        {
            // Perform OCR on the input image
            var Result = Ocr.Read(Input);

            // Get the extracted text
            var AllText = Result.Text;

            // Output the extracted text to the console
            System.Console.WriteLine(AllText);
        }
    }
}
' Import the IronOcr namespace
Imports IronOcr

Friend Class BengaliOcrExample
	Shared Sub Main()
		' Create an instance of IronTesseract
		Dim Ocr = New IronTesseract()

		' Specify the language for OCR
		Ocr.Language = OcrLanguage.Bengali

		' Process the image and extract text
		Using Input = New OcrInput("images\Bengali.png")
			' Perform OCR on the input image
			Dim Result = Ocr.Read(Input)

			' Get the extracted text
			Dim AllText = Result.Text

			' Output the extracted text to the console
			System.Console.WriteLine(AllText)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

解释

1.导入 IronOcr:我们首先导入IronOcr命名空间,其中包含执行 OCR 操作所需的类和方法。

2.创建 IronTesseract 实例:我们创建一个IronTesseract实例,它是执行 OCR 的主要类。

3.设置语言:我们使用OcrLanguage.Bengali将 OCR 语言设置为孟加拉语。

  1. OcrInput:我们指定要从中提取文本的图像路径。 使用OcrInput对象来加载和预处理输入文件。

5.读取和提取文本:使用Read方法,我们处理图像以读取文本内容。 文本存储在Result.Text中。

6.输出文本:最后,我们将提取的文本打印到控制台以验证输出。