C# 和 .NET 中的斯瓦希里语 OCR

This article was translated from English: Does it need improvement?
Translated
View the article in English

本文档的其他版本

斯瓦希里语 新增 125 种 OCR 语言

IronOCR 是一个 C# 软件组件,允许 .NET 程序员从图像和 PDF 文档中读取 126 种语言(包括斯瓦希里语)的文本。 它是 Tesseract 的一个高级分支,专为 .NET 开发人员构建,在速度和准确性方面通常优于其他 Tesseract 引擎。

IronOcr.Languages.Swahili 的内容

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

  • 斯瓦希里语
  • 斯瓦希里语Best
  • 斯瓦希里语Fast

下载

斯瓦希里语语言包 [斯瓦希里语]

安装

我们首先需要做的是将我们的斯瓦希里语OCR 包安装到您的 .NET 项目中。

Install-Package IronOCR.Languages.Swahili

代码示例

这段 C# 代码示例从图像或 PDF 文档中读取斯瓦希里语文本。

using IronOcr;

var Ocr = new IronTesseract();

// Set the OCR language to Swahili
Ocr.Language = OcrLanguage.Swahili;

// Create an OCR input for the image or PDF file
using (var Input = new OcrInput(@"images\Swahili.png"))
{
    // Perform OCR on the input image
    var Result = Ocr.Read(Input);

    // Retrieve the recognized text
    var AllText = Result.Text;

    // Output the recognized text to the console (optional)
    Console.WriteLine(AllText);
}
using IronOcr;

var Ocr = new IronTesseract();

// Set the OCR language to Swahili
Ocr.Language = OcrLanguage.Swahili;

// Create an OCR input for the image or PDF file
using (var Input = new OcrInput(@"images\Swahili.png"))
{
    // Perform OCR on the input image
    var Result = Ocr.Read(Input);

    // Retrieve the recognized text
    var AllText = Result.Text;

    // Output the recognized text to the console (optional)
    Console.WriteLine(AllText);
}
Imports IronOcr

Private Ocr = New IronTesseract()

' Set the OCR language to Swahili
Ocr.Language = OcrLanguage.Swahili

' Create an OCR input for the image or PDF file
Using Input = New OcrInput("images\Swahili.png")
	' Perform OCR on the input image
	Dim Result = Ocr.Read(Input)

	' Retrieve the recognized text
	Dim AllText = Result.Text

	' Output the recognized text to the console (optional)
	Console.WriteLine(AllText)
End Using
$vbLabelText   $csharpLabel
  • PdfWriter:此对象负责写入PDF文件。它作用于文件路径,并写入有效PDF文档所需的结构。

1.使用 IronOcr 命名空间:我们引入IronOcr命名空间,该命名空间提供用于 OCR 操作的类和方法。

2.初始化 OCR 引擎:我们创建一个IronTesseract实例,它就是 OCR 引擎。将其语言设置为斯瓦希里语,即可使其识别斯瓦希里语文本。

  1. OCR 输入OcrInput类用于指定要从中提取文本的文件(图像或 PDF)。

  2. OCR 读取Read方法处理输入并返回一个包含识别文本的OcrResult对象。

5.输出:识别出的文本存储在AllText中,可根据需要使用。 在这个例子中,为了演示目的,它会被打印到控制台。