How to use Custom Language with Tesseract

This article was translated from English: Does it need improvement?
Translated
View the article in English

When it comes to optical character recognition (OCR), you sometimes need to deal with custom languages, specialized scripts, or ciphers. To read an input image containing a custom language, the Tesseract engine must be provided with training data for that specific language. This data is stored in a special .traineddata file.

While the complex process of creating (training) this file is done using Tesseract's own tools, IronOCR fully supports using these custom language files. This lets you apply your trained model to decipher and read text from any input. In this how-to guide, we'll showcase how to load and use a custom .traineddata file with IronOCR.

Get started with IronOCR

今日あなたのプロジェクトでIronOCRを無料トライアルで使用開始。

最初のステップ:
green arrow pointer


Custom Language with Tesseract

To use a custom language with Tesseract, we must first load our .traineddata file by calling the UseCustomTesseractLanguageFile method. This is an essential step, as this file contains all the training data that allows Tesseract to recognize the custom language's unique characters.

Afterward, we load our input document just as we would for a regular OCR operation. In this instance, we are loading a PDF containing custom language paragraphs using LoadPdf.

Finally, we use the Read method to extract the text from the input. The result can then be printed to the console or, as the example shows, saved (piped) to a text file for reference.

Input

We'll use this sample PDF, which contains text in our custom language, as the input.

We'll be using this custom language .traindata for our example.

Code Example

:path=/static-assets/ocr/content-code-examples/how-to/ocr-custom-language.cs
using IronOcr;
using System;
using System.IO;

var ocrTesseract = new IronTesseract();

// Load the traineddata file for the custom language
ocrTesseract.UseCustomTesseractLanguageFile("AMGDT.traineddata");

using var ocrInput = new OcrInput();
// Load the PDF containing text in the custom language
ocrInput.LoadPdf("custom.pdf");

var ocrResult = ocrTesseract.Read(ocrInput);

// Print text to the console
Console.WriteLine("--- OCR Result ---");
Console.WriteLine(ocrResult.Text);
Console.WriteLine("------------------");

// Pipe text to a .txt file
string outputFilePath = "ocr_output.txt";
File.WriteAllText(outputFilePath, ocrResult.Text);

Console.WriteLine($"\nSuccessfully saved text to {outputFilePath}");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

OCR Output text

This output shows the result from our custom language model. As you can see, by providing the correct training data, IronOCR successfully deciphered the text, and the result is in plain English. Additionally, this is the txt output generated by the code.

よくある質問

IronOCR で Tesseract を使用したカスタム言語を使用する目的は何ですか?

IronOCRのTesseractでカスタム言語を使用すると、デフォルトではサポートされていない特殊な文字や言語を含む画像やPDFからテキストを認識し、抽出できます。これは、その言語に必要なトレーニングデータを含むカスタムの`.traineddata`ファイルを読み込むことで実現されます。

IronOCR にカスタム言語トレーニング データ ファイルを読み込むにはどうすればよいでしょうか?

IronOCRでは、`UseCustomTesseractLanguageFile`メソッドを使用して、カスタム言語のトレーニングデータファイルを読み込むことができます。このステップは、カスタム言語固有の文字を認識するために必要なトレーニングデータをTesseractエンジンに提供するため、非常に重要です。

IronOCR を使用してカスタム言語で画像に対して OCR を実行する手順は何ですか?

IronOCR を使用してカスタム言語で画像に対して OCR を実行するには、まず C# ライブラリをダウンロードし、OCR エンジンを初期化し、`UseCustomTesseractLanguageFile` を使用してカスタム言語のトレーニング データを読み込み、`LoadImage` を使用して入力画像を読み込み、最後に `Read` メソッドを使用してテキストを抽出します。

IronOCR はカスタム言語テキストを含む PDF を処理できますか?

はい、IronOCRはカスタム言語テキストを含むPDFを処理できます。`LoadPdf`メソッドを使用してPDFを読み込み、`Read`メソッドを使用して、提供されたカスタム言語トレーニングデータに基づいてテキストを抽出できます。

Tesseract および IronOCR のコンテキストにおける `.traineddata` ファイルとは何ですか?

`.traineddata` ファイルは、Tesseract OCR で使用されるデータファイルで、特定の言語のトレーニングデータが含まれています。このファイルにより、OCR エンジンは特定の言語の文字を認識して処理できるようになり、IronOCR でカスタム言語を処理する際にも利用できます。

IronOCR のすべてのカスタム言語に対して独自の `.traineddata` ファイルを作成する必要がありますか?

いいえ、カスタム言語ごとに独自の `.traineddata` ファイルを作成する必要はありません。既存の `.traineddata` ファイルがある場合は、それを使用できます。ただし、特定の言語がサポートされていない場合は、Tesseract のツールを使用して作成する必要がある場合があります。

カスタム言語を使用する場合、IronOCR ではどのような出力形式がサポートされますか?

IronOCRは、カスタム言語を使用する場合、コンソールに出力したりテキストファイルに保存したりできるプレーンテキスト出力など、様々な出力形式をサポートしています。抽出されたテキストは、必要に応じてさらに加工することができます。

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 5,044,537 | バージョン: 2025.11 ただ今リリースされました