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

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

  • 拉脱维亚语
  • LatvianBest
  • LatvianFast

下载

拉脱维亚语语言包[拉脱维亚语]

安装

首先,你需要将拉脱维亚语OCR 包安装到你的 .NET 项目中。

Install-Package IronOCR.Languages.Latvian

代码示例

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

using IronOcr;

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

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

        // Define the input image file path
        using (var Input = new OcrInput(@"images\Latvian.png"))
        {
            // Perform OCR on the input image
            var Result = Ocr.Read(Input);

            // Extract all recognized text from the OCR result
            var AllText = Result.Text;

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

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

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

        // Define the input image file path
        using (var Input = new OcrInput(@"images\Latvian.png"))
        {
            // Perform OCR on the input image
            var Result = Ocr.Read(Input);

            // Extract all recognized text from the OCR result
            var AllText = Result.Text;

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

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

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

		' Define the input image file path
		Using Input = New OcrInput("images\Latvian.png")
			' Perform OCR on the input image
			Dim Result = Ocr.Read(Input)

			' Extract all recognized text from the OCR result
			Dim AllText = Result.Text

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

解释

  • IronOcr 命名空间:示例首先导入IronOcr命名空间,这是访问 OCR 功能所必需的。
  • IronTesseract 实例:创建IronTesseract对象( Ocr )是为了处理图像读取和文本提取。 -语言配置:通过设置Ocr.Language属性,将 OCR 过程配置为读取拉脱维亚语文本。
  • OcrInput 对象:创建一个OcrInput对象,引用要处理的图像文件。 -读取图像:调用Ocr实例的Read方法来处理图像并提取文本,并将结果存储在Result变量中。 -结果提取:通过Result.Text访问 OCR 结果,并将其存储在AllText中以供进一步使用或显示。 -控制台输出:识别出的拉脱维亚语文本会打印到控制台上,从而提供文本提取的视觉确认。