Latvian OCR in C# and .NET

This article was translated from English: Does it need improvement?
Translated
View the article in English
本文件的其他版本:

IronOCR 是一款 C# 軟體元件,讓 .NET 開發人員能夠從 126 種語言(包括拉脫維亞語)的圖片和 PDF 文件中讀取文字。

這是 Tesseract 的進階分支版本,專為 .NET 開發人員打造,無論在速度或準確度方面,其表現均經常優於其他 Tesseract 引擎。

IronOcr.Languages.Latvian 的內容

此套件包含 46 種適用於 .NET 的 OCR 語言:

  • 拉脫維亞語
  • 拉脫維亞語最佳
  • 拉脫維亞語Fast

下載

拉脫維亞語語言包 [latviešu valoda]

安裝

您首先需要將拉脫維亞語 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 物件,並參照待處理的影像檔案。
  • 讀取影像:Read 實例上呼叫 Ocr 方法,以處理影像並擷取文字,並將其儲存於 Result 變數中。
  • 結果擷取:可透過 Result.Text 存取 OCR 結果,並將其儲存於 AllText 中,以供後續使用或顯示。
  • 主控台輸出:識別出的拉脫維亞文文字將輸出至主控台,以視覺方式確認文字已成功擷取。