使用 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.Bengali 的內容

此軟體包包含 114 種適用於 .NET 的 OCR 語言:

  • 孟加拉語
  • BengaliBest
  • BengaliFast
  • 孟加拉字母
  • BengalaliAlphabetBest
  • BengalaliAlphabetFast

下載

孟加拉語語言包[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
$vbLabelText   $csharpLabel

說明

1.導入 IronOcr:我們首先導入IronOcr命名空間,其中包含執行 OCR 操作所需的類別和方法。

2.建立 IronTesseract 實例:我們建立一個IronTesseract實例,它是執行 OCR 的主要類別。

3.設定語言:我們使用OcrLanguage.Bengali將 OCR 語言設定為孟加拉語。

  1. OcrInput:我們指定要從中提取文字的圖像路徑。 使用OcrInput物件來載入和預處理輸入檔。

5.讀取和提取文字:使用Read方法,我們處理圖像以讀取文字內容。 文字儲存在Result.Text

6.輸出文字:最後,我們將提取的文字列印到控制台以驗證輸出。