Bengali OCR in C# and .NET
本文档的其他版本:
IronOCR 是一个 C# 软件组件,允许 .NET 程序员从图像和 PDF 文档中读取 126 种语言(包括孟加拉语)的文本。 它是 Tesseract 的一个高级分支,专为 .NET 开发人员构建,在速度和准确性方面通常优于其他 Tesseract 引擎。
IronOcr.Languages.Bengali 的内容
此软件包包含 114 种适用于 .NET 的 OCR 语言:
- 孟加拉语
- 孟加拉语Best
- 孟加拉语Fast
- 孟加拉语字母表
- 孟加拉语字母表Best
- 孟加拉语字母快速
下载
孟加拉语语言包[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
解释
-
导入 IronOCR:首先导入
IronOcr命名空间,其中包含执行 OCR 操作所需的类和方法。 -
创建 IronTesseract 实例:我们创建
IronTesseract的实例,该类是执行 OCR 功能的核心类。 -
设置语言:我们使用
OcrLanguage.Bengali将 OCR 语言设置为孟加拉语。 -
OcrInput:我们指定要从中提取文本的图像路径。 使用
OcrInput对象来加载并预处理输入文件。 - 读取并提取文本:使用
Read方法,我们对图像进行处理以读取文本内容。 文本存储在Result.Text中。
6.输出文本:最后,我们将提取的文本打印到控制台以验证输出。

