Swahili 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.Swahili 的內容

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

  • 斯瓦希里語
  • 斯瓦希里語Best
  • 斯瓦希里語Fast

下載

斯瓦希里語語言套件 [Kiswahili]

安裝

我們首先必須將斯瓦希里語 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

說明:

  1. 使用 IronOCR 命名空間:我們包含 IronOcr 命名空間,該命名空間提供用於 OCR 操作的類別與方法。

  2. 初始化 OCR 引擎:我們建立 IronTesseract 的實例,此為 OCR 引擎。將其語言設定為斯瓦希里語,即可使其識別斯瓦希里語文字。

  3. OCR 輸入:使用 OcrInput 類別來指定欲從中擷取文字的檔案(圖片或 PDF)。

  4. OCR 讀取Read 方法會處理輸入內容,並返回一個包含已識別文字的 OcrResult 物件。

  5. 輸出:識別出的文字儲存於 AllText 中,可依需求使用。 在此範例中,為示範目的,內容將輸出至控制台。