C# 與 .NET 中的泰文 OCR

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

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

  • 泰語
  • 泰語Best
  • 泰語Fast
  • 泰文字母
  • 泰文字母Best
  • 泰文字母Fast

下載

泰文語言套件 [ไทย]

安裝

首先,我們必須將泰文字母 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);
        }
    }
}
Imports IronOcr

Class ThaiOcrExample
    Shared Sub Main()
        ' Create a new instance of IronTesseract for OCR processing
        Dim ocr As 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 As 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 指定泰語語言套件進行辨識。