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

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

  • 泰語
  • ThaiBest
  • ThaiFast
  • 泰文字母
  • ThaiAlphabetBest
  • ThaiAlphabetFast

下載

泰語字母語言包[ไทย]

安裝

我們首先需要做的就是將我們的泰文字母OCR 套件安裝到您的 .NET 專案中。

Install-Package IronOCR.Languages.Thai

程式碼範例

這段 C# 程式碼範例從圖像或 PDF 文件中讀取泰語字母文字。

// Ensure you have installed the IronOCR.Languages.Thai package via NuGet.
// Import the IronOcr namespace to work with IronOCR classes.
using IronOcr; 

class ThaiOcrExample
{
    static void Main()
    {
        // Create a new instance of IronTesseract for OCR processing
        var ocr = new IronTesseract();

        // Set the language to Thai for Optical Character Recognition
        ocr.Language = OcrLanguage.Thai;

        // Using the 'using' statement ensures that resources are properly disposed.
        using (var input = new OcrInput(@"images\Thai.png"))
        {
            // Perform OCR to read the text from the input image
            var result = ocr.Read(input);

            // Retrieve and store all recognized text from the image
            string allText = result.Text;

            // Optionally, you can output the text to console or log it as needed
            System.Console.WriteLine(allText);
        }
    }
}
// Ensure you have installed the IronOCR.Languages.Thai package via NuGet.
// Import the IronOcr namespace to work with IronOCR classes.
using IronOcr; 

class ThaiOcrExample
{
    static void Main()
    {
        // Create a new instance of IronTesseract for OCR processing
        var ocr = new IronTesseract();

        // Set the language to Thai for Optical Character Recognition
        ocr.Language = OcrLanguage.Thai;

        // Using the 'using' statement ensures that resources are properly disposed.
        using (var input = new OcrInput(@"images\Thai.png"))
        {
            // Perform OCR to read the text from the input image
            var result = ocr.Read(input);

            // Retrieve and store all recognized text from the image
            string allText = result.Text;

            // Optionally, you can output the text to console or log it as needed
            System.Console.WriteLine(allText);
        }
    }
}
' Ensure you have installed the IronOCR.Languages.Thai package via NuGet.
' Import the IronOcr namespace to work with IronOCR classes.
Imports IronOcr

Friend Class ThaiOcrExample
	Shared Sub Main()
		' Create a new instance of IronTesseract for OCR processing
		Dim ocr = New IronTesseract()

		' Set the language to Thai for Optical Character Recognition
		ocr.Language = OcrLanguage.Thai

		' Using the 'using' statement ensures that resources are properly disposed.
		Using input = New OcrInput("images\Thai.png")
			' Perform OCR to read the text from the input image
			Dim result = ocr.Read(input)

			' Retrieve and store all recognized text from the image
			Dim allText As String = result.Text

			' Optionally, you can output the text to console or log it as needed
			System.Console.WriteLine(allText)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

在這個例子中,我們從位於images夾中的名為Thai.png圖像中讀取泰文文字。 請務必將檔案路徑替換為您實際的圖片位置。 OCR 語言設定為泰語,使用OcrLanguage.Thai指定要辨識的泰語語言套件。