C# OCR Image to Text Tutorial: Convert Images to Text Without Tesseract
複雑な Tesseract 構成の手間をかけずに、C# で画像をテキストに変換したいとお考えですか? この包括的な IronOCR C# チュートリアルでは、わずか数行のコードで .NET アプリケーションに強力な光学式文字認識を実装する方法を説明します。
クイックスタート:1行で画像からテキストを抽出する
この例では、IronOCR を理解するのがいかに簡単かを示しています。たった 1 行の C# で画像がテキストに変換されます。 OCR エンジンを初期化し、複雑な設定なしですぐにテキストを読み取って取得する方法を示します。
最小限のワークフロー(5ステップ)
- IronOCRをダウンロード - 画像からテキストへの変換用C#OCRライブラリ
IronTesseractクラスを使用して画像からテキストを即座に読み取ります- 画像フィルターを適用して、低品質のスキャンの OCR 精度を高めます
- ダウンロード可能な言語パックを使用して複数の言語を処理
- 結果を検索可能なPDFとしてエクスポートするか、テキスト文字列を抽出します
.NET アプリケーションで画像からテキストを読み取るにはどうすればよいでしょうか?
.NET アプリケーションで C# OCR 画像からテキストへの機能を実現するには、信頼性の高い OCR ライブラリが必要です。 IronOCRは、IronOcr.IronTesseractクラスを使用したマネージドソリューションを提供し、外部依存関係を必要とせずに精度と速度の両方を最大化します。
まず、Visual Studio プロジェクトに IronOCR をインストールします。 IronOCR DLL を直接ダウンロードするか、 NuGet パッケージ マネージャーを使用することができます。
Install-Package IronOcr
Tesseract なしの C# OCR に IronOCR を選択する理由
C# で画像をテキストに変換する必要がある場合、IronOCR は従来の Tesseract 実装に比べて大きな利点を提供します。
- 純粋な.NET環境ですぐに動作します
- Tesseractのインストールや設定は不要
- 最新のエンジンを実行: Tesseract 5 (および Tesseract 4 と 3)
- .NET Framework 4.6.2 以降、.NET Standard 2 以降、および .NET Core 2、3、5、6、7、8、9、10 に対応
- バニラのTesseractと比較して精度と速度が向上します
- Xamarin、Mono、Azure、Docker のデプロイメントをサポート
- NuGet パッケージを通じて複雑な Tesseract 辞書を管理します
- PDF、マルチフレームTIFF、およびすべての主要な画像形式を自動的に処理します
- 低品質や歪んだスキャンを補正して最適な結果を実現します
基本的な OCR に IronOCR C# チュートリアルを使用するにはどうすればよいでしょうか?
この Iron Tesseract C# の例では、IronOCR を使用して画像からテキストを読み取る最も簡単な方法を示します。 IronOcr.IronTesseract クラスはテキストを抽出し、文字列として返します。
// Basic C# OCR image to text conversion using IronOCR
// This example shows how to extract text from images without complex setup
using IronOcr;
using System;
try
{
// Initialize IronTesseract for OCR operations
var ocrEngine = new IronTesseract();
// Path to your image file - supports PNG, JPG, TIFF, BMP, and more
var imagePath = @"img\Screenshot.png";
// Create input and perform OCR to convert image to text
using (var input = new OcrInput(imagePath))
{
// Read text from image and get results
OcrResult result = ocrEngine.Read(input);
// Display extracted text
Console.WriteLine(result.Text);
}
}
catch (OcrException ex)
{
// Handle OCR-specific errors
Console.WriteLine($"OCR Error: {ex.Message}");
}
catch (Exception ex)
{
// Handle general errors
Console.WriteLine($"Error: {ex.Message}");
}
// Basic C# OCR image to text conversion using IronOCR
// This example shows how to extract text from images without complex setup
using IronOcr;
using System;
try
{
// Initialize IronTesseract for OCR operations
var ocrEngine = new IronTesseract();
// Path to your image file - supports PNG, JPG, TIFF, BMP, and more
var imagePath = @"img\Screenshot.png";
// Create input and perform OCR to convert image to text
using (var input = new OcrInput(imagePath))
{
// Read text from image and get results
OcrResult result = ocrEngine.Read(input);
// Display extracted text
Console.WriteLine(result.Text);
}
}
catch (OcrException ex)
{
// Handle OCR-specific errors
Console.WriteLine($"OCR Error: {ex.Message}");
}
catch (Exception ex)
{
// Handle general errors
Console.WriteLine($"Error: {ex.Message}");
}
' Basic C# OCR image to text conversion using IronOCR
' This example shows how to extract text from images without complex setup
Imports IronOcr
Imports System
Try
' Initialize IronTesseract for OCR operations
Dim ocrEngine = New IronTesseract()
' Path to your image file - supports PNG, JPG, TIFF, BMP, and more
Dim imagePath = "img\Screenshot.png"
' Create input and perform OCR to convert image to text
Using input = New OcrInput(imagePath)
' Read text from image and get results
Dim result As OcrResult = ocrEngine.Read(input)
' Display extracted text
Console.WriteLine(result.Text)
End Using
Catch ex As OcrException
' Handle OCR-specific errors
Console.WriteLine($"OCR Error: {ex.Message}")
Catch ex As Exception
' Handle general errors
Console.WriteLine($"Error: {ex.Message}")
End Try
このコードは鮮明な画像に対して 100% の精度を実現し、表示されているとおりにテキストを抽出します。
IronOCR Simple Example
In this simple example we test the accuracy of our C# OCR library to read text from a PNG Image. This is a very basic test, but things will get more complicated as the tutorial continues.
The quick brown fox jumps over the lazy dog
IronTesseract クラスは、内部で複雑な OCR 処理を処理します。 自動的に位置合わせをスキャンし、解像度を最適化し、AI を使用して IronOCR で人間レベルの精度で画像からテキストを読み取ります。
画像分析、エンジン最適化、インテリジェントなテキスト認識などの高度な処理がバックグラウンドで行われているにもかかわらず、OCR プロセスは人間の読み取り速度に匹敵し、並外れた精度レベルを維持しています。
IronOCR が PNG 画像から完璧な精度でテキストを抽出できることを示すスクリーンショット
Tesseract 構成なしで高度な C# OCR を実装する方法
C#で画像をテキストに変換する際、最適なパフォーマンスが求められる本番環境のアプリケーションでは、OcrInput クラスと IronTesseract クラスを組み合わせて使用してください。 このアプローチにより、OCR プロセスをきめ細かく制御できます。
OcrInputクラスの機能
- 複数の画像形式を処理: JPEG、TIFF、GIF、BMP、PNG
- PDF全体または特定のページをインポートします
- コントラスト、解像度、画質を自動的に向上します
- 回転、スキャンノイズ、傾き、ネガティブイメージを修正します
IronTesseractクラスの機能
- 127以上のプリパッケージされた言語へのアクセス
- Tesseract 5、4、3エンジン搭載
- ドキュメントタイプの指定(スクリーンショット、スニペット、または完全なドキュメント)
- 統合バーコード読み取り機能
- 複数の出力形式: 検索可能なPDF、HOCR HTML、DOMオブジェクト、文字列
OcrInput と IronTesseract を使い始めるにはどうすればいいですか?
ほとんどのドキュメント タイプで適切に機能する、この IronOCR C# チュートリアルの推奨構成は次のとおりです。
using IronOcr;
// Initialize IronTesseract for advanced OCR operations
IronTesseract ocr = new IronTesseract();
// Create input container for processing multiple images
using (OcrInput input = new OcrInput())
{
// Process specific pages from multi-page TIFF files
int[] pageIndices = new int[] { 1, 2 };
// Load TIFF frames - perfect for scanned documents
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Execute OCR to read text from image using IronOCR
OcrResult result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
using IronOcr;
// Initialize IronTesseract for advanced OCR operations
IronTesseract ocr = new IronTesseract();
// Create input container for processing multiple images
using (OcrInput input = new OcrInput())
{
// Process specific pages from multi-page TIFF files
int[] pageIndices = new int[] { 1, 2 };
// Load TIFF frames - perfect for scanned documents
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Execute OCR to read text from image using IronOCR
OcrResult result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
Imports IronOcr
' Initialize IronTesseract for advanced OCR operations
Private ocr As New IronTesseract()
' Create input container for processing multiple images
Using input As New OcrInput()
' Process specific pages from multi-page TIFF files
Dim pageIndices() As Integer = { 1, 2 }
' Load TIFF frames - perfect for scanned documents
input.LoadImageFrames("img\Potter.tiff", pageIndices)
' Execute OCR to read text from image using IronOCR
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text
Console.WriteLine(result.Text)
End Using
この構成では、中品質のスキャンでほぼ完璧な精度が一貫して達成されます。 LoadImageFrames メソッドは、複数ページのドキュメントを効率的に処理するため、バッチ処理のシナリオに最適です。
IronOCR の複数ページテキスト抽出機能を示すサンプル TIFF ドキュメント
TIFF などのスキャンされたドキュメント内の画像やバーコードからテキストを読み取る機能は、IronOCR が複雑な OCR タスクをいかに簡素化するかを示しています。 このライブラリは実際のドキュメントに優れており、複数ページの TIFF とPDF テキスト抽出をシームレスに処理します。
IronOCR は低品質のスキャンをどのように処理しますか?
IronOCRが画像フィルターを使用して正確に処理できるノイズのある低解像度の文書
歪みやデジタル ノイズを含む不完全なスキャンを処理する場合、 IronOCR は他の C# OCR ライブラリよりも優れたパフォーマンスを発揮します。 これは、純粋なテスト画像ではなく、現実世界のシナリオ向けに特別に設計されています。
// Advanced Iron Tesseract C# example for low-quality images
using IronOcr;
using System;
var ocr = new IronTesseract();
try
{
using (var input = new OcrInput())
{
// Load specific pages from poor-quality TIFF
var pageIndices = new int[] { 0, 1 };
input.LoadImageFrames(@"img\Potter.LowQuality.tiff", pageIndices);
// Apply deskew filter to correct rotation and perspective
input.Deskew(); // Critical for improving accuracy on skewed scans
// Perform OCR with enhanced preprocessing
OcrResult result = ocr.Read(input);
// Display results
Console.WriteLine("Recognized Text:");
Console.WriteLine(result.Text);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error during OCR: {ex.Message}");
}
// Advanced Iron Tesseract C# example for low-quality images
using IronOcr;
using System;
var ocr = new IronTesseract();
try
{
using (var input = new OcrInput())
{
// Load specific pages from poor-quality TIFF
var pageIndices = new int[] { 0, 1 };
input.LoadImageFrames(@"img\Potter.LowQuality.tiff", pageIndices);
// Apply deskew filter to correct rotation and perspective
input.Deskew(); // Critical for improving accuracy on skewed scans
// Perform OCR with enhanced preprocessing
OcrResult result = ocr.Read(input);
// Display results
Console.WriteLine("Recognized Text:");
Console.WriteLine(result.Text);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error during OCR: {ex.Message}");
}
' Advanced Iron Tesseract C# example for low-quality images
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
Try
Using input = New OcrInput()
' Load specific pages from poor-quality TIFF
Dim pageIndices = New Integer() { 0, 1 }
input.LoadImageFrames("img\Potter.LowQuality.tiff", pageIndices)
' Apply deskew filter to correct rotation and perspective
input.Deskew() ' Critical for improving accuracy on skewed scans
' Perform OCR with enhanced preprocessing
Dim result As OcrResult = ocr.Read(input)
' Display results
Console.WriteLine("Recognized Text:")
Console.WriteLine(result.Text)
End Using
Catch ex As Exception
Console.WriteLine($"Error during OCR: {ex.Message}")
End Try
Input.Deskew()を使用すると、低品質なスキャン画像でも精度が99.8%に向上し、高品質なスキャン画像の結果にほぼ匹敵するようになります。 これは、Tesseract の複雑さがなく、C# OCR に IronOCR が最適な選択肢である理由を示しています。
画像フィルターにより処理時間がわずかに長くなる可能性がありますが、全体的な OCR の所要時間が大幅に短縮されます。 適切なバランスを見つけるには、ドキュメントの品質が重要になります。
ほとんどのシナリオにおいて、Input.Deskew() および Input.DeNoise() は、OCRのパフォーマンスを確実に改善します。 画像前処理技術について詳しく学びます。
OCR のパフォーマンスと速度を最適化するにはどうすればよいでしょうか?
C# で画像をテキストに変換するときに OCR 速度に影響を与える最も重要な要素は、入力品質です。 ノイズが最小限で DPI がより高い (約 200 dpi) 場合、最も高速かつ正確な結果が得られます。
IronOCR は不完全な文書の修正に優れていますが、この機能強化には追加の処理時間が必要になります。
圧縮アーティファクトが最小限の画像形式を選択します。 TIFF と PNG は通常、デジタル ノイズが少ないため、JPEG よりも結果が速くなります。
どの画像フィルターが OCR 速度を向上させるのでしょうか?
次のフィルターを使用すると、C# OCR 画像からテキストへのワークフローのパフォーマンスを大幅に向上できます。
OcrInput.Rotate(double degrees): 画像を時計回りに回転させます(反時計回りにする場合は負の値を指定します)OcrInput.Binarize(): 白黒に変換し、コントラストの低い環境でのパフォーマンスを向上させますOcrInput.ToGrayScale(): 処理速度向上の可能性を考慮し、グレースケールに変換OcrInput.Contrast(): 精度向上のためにコントラストを自動調整しますOcrInput.DeNoise(): ノイズが予想される場合にデジタルアーティファクトを除去しますOcrInput.Invert(): 文字色を反転(白文字・黒背景)OcrInput.Dilate(): テキストの境界を拡張しますOcrInput.Erode(): テキストの境界を縮小しますOcrInput.Deskew(): 配置を修正 - 歪んだ文書には不可欠OcrInput.DeepCleanBackgroundNoise(): 強力なノイズ除去OcrInput.EnhanceResolution: 低解像度画像の画質を向上させますOcrInput.DetectPageOrientation(): ページの回転を検出し、修正します。OrientationDetectionModeを指定して、正確性と速度のバランスを調整してください:Detailed、またはExtremeDetailed(v2025.8.6で追加)
Scale() および EnhanceResolution() は、v2025.12.3 の既知の問題により、SaveAsSearchablePdf() と互換性がありません。その他のすべてのフィルターは、検索可能な PDF 出力において正常に動作します。
IronOCR を最高速度で設定するにはどうすればいいですか?
高品質のスキャンを処理する際の速度を最適化するには、次の設定を使用します。
using IronOcr;
// Configure for speed - ideal for clean documents
IronTesseract ocr = new IronTesseract();
// Exclude problematic characters to speed up recognition
ocr.Configuration.BlackListCharacters = "~`$#^*_{[]}|\\";
// Use automatic page segmentation
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
// Select fast English language pack
ocr.Language = OcrLanguage.EnglishFast;
using (OcrInput input = new OcrInput())
{
// Load specific pages from document
int[] pageIndices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Read with optimized settings
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
using IronOcr;
// Configure for speed - ideal for clean documents
IronTesseract ocr = new IronTesseract();
// Exclude problematic characters to speed up recognition
ocr.Configuration.BlackListCharacters = "~`$#^*_{[]}|\\";
// Use automatic page segmentation
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
// Select fast English language pack
ocr.Language = OcrLanguage.EnglishFast;
using (OcrInput input = new OcrInput())
{
// Load specific pages from document
int[] pageIndices = new int[] { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
// Read with optimized settings
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
Imports IronOcr
' Configure for speed - ideal for clean documents
Private ocr As New IronTesseract()
' Exclude problematic characters to speed up recognition
ocr.Configuration.BlackListCharacters = "~`$#^*_{[]}|\"
' Use automatic page segmentation
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto
' Select fast English language pack
ocr.Language = OcrLanguage.EnglishFast
Using input As New OcrInput()
' Load specific pages from document
Dim pageIndices() As Integer = { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageIndices)
' Read with optimized settings
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
この最適化された設定により、デフォルト設定と比較して35% の速度向上を実現しながら、 99.8% の精度が維持されます。
C# OCR を使用して画像の特定の領域を読み取るにはどうすればよいでしょうか?
以下の Iron Tesseract C# の例は、System.Drawing.Rectangle を使用して特定の地域をターゲットにする方法を示しています。 この手法は、テキストが予測可能な場所に表示される標準化されたフォームを処理する場合に非常に役立ちます。
IronOCR は切り取られた領域を処理してより速く結果を得ることができますか?
ピクセルベースの座標を使用すると、OCR を特定の領域に制限できるため、速度が大幅に向上し、不要なテキストの抽出を防ぐことができます。
using IronOcr;
using IronSoftware.Drawing;
// Initialize OCR engine for targeted region processing
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Define exact region for OCR - coordinates in pixels
var contentArea = new System.Drawing.Rectangle(
x: 215,
y: 1250,
width: 1335,
height: 280
);
// Load image with specific area - perfect for forms and invoices
input.LoadImage("img/ComSci.png", contentArea);
// Process only the defined region
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
using IronOcr;
using IronSoftware.Drawing;
// Initialize OCR engine for targeted region processing
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Define exact region for OCR - coordinates in pixels
var contentArea = new System.Drawing.Rectangle(
x: 215,
y: 1250,
width: 1335,
height: 280
);
// Load image with specific area - perfect for forms and invoices
input.LoadImage("img/ComSci.png", contentArea);
// Process only the defined region
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
Imports IronOcr
Imports IronSoftware.Drawing
' Initialize OCR engine for targeted region processing
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Define exact region for OCR - coordinates in pixels
Dim contentArea As New System.Drawing.Rectangle(215, 1250, 1335, 280)
' Load image with specific area - perfect for forms and invoices
input.LoadImage("img/ComSci.png", contentArea)
' Process only the defined region
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
このターゲットを絞ったアプローチにより、関連するテキストのみを抽出しながら、速度が 41% 向上します。 請求書、小切手、フォームなどの構造化された文書に最適です。 同じ切り取り手法は、PDF OCR 操作でもシームレスに機能します。
IronOCRの長方形選択を使用した正確な領域ベースのテキスト抽出を示すドキュメント
IronOCR はいくつの言語をサポートしていますか?
IronOCRは、便利な言語パックを通じて127の国際言語に対応しています。 当社の Web サイトまたはNuGet パッケージ マネージャーから DLL としてダウンロードします。
NuGet インターフェイス ( "IronOcr.Languages"を検索) を通じて言語パックをインストールするか、完全な言語パックのリストにアクセスしてください。
サポートされている言語には、アラビア語、中国語(簡体字/繁体字)、日本語、韓国語、ヒンディー語、ロシア語、ドイツ語、フランス語、スペイン語など 115 以上の言語があり、それぞれ正確なテキスト認識が最適化されています。
複数の言語で OCR を実装するにはどうすればよいでしょうか?
この IronOCR C# チュートリアルの例では、アラビア語のテキスト認識を示します。
Install-Package IronOcr.Languages.Arabic
IronOCRはGIF画像からアラビア語のテキストを正確に抽出します
// Install-Package IronOcr.Languages.Arabic
using IronOcr;
// Configure for Arabic language OCR
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using (var input = new OcrInput())
{
// Load Arabic text image
input.LoadImage("img/arabic.gif");
// IronOCR handles low-quality Arabic text that standard Tesseract cannot
var result = ocr.Read(input);
// Save to file (console may not display Arabic correctly)
result.SaveAsTextFile("arabic.txt");
}
// Install-Package IronOcr.Languages.Arabic
using IronOcr;
// Configure for Arabic language OCR
var ocr = new IronTesseract();
ocr.Language = OcrLanguage.Arabic;
using (var input = new OcrInput())
{
// Load Arabic text image
input.LoadImage("img/arabic.gif");
// IronOCR handles low-quality Arabic text that standard Tesseract cannot
var result = ocr.Read(input);
// Save to file (console may not display Arabic correctly)
result.SaveAsTextFile("arabic.txt");
}
Imports IronOcr
' Configure for Arabic language OCR
Dim ocr As New IronTesseract()
ocr.Language = OcrLanguage.Arabic
Using input As New OcrInput()
' Load Arabic text image
input.LoadImage("img/arabic.gif")
' IronOCR handles low-quality Arabic text that standard Tesseract cannot
Dim result = ocr.Read(input)
' Save to file (console may not display Arabic correctly)
result.SaveAsTextFile("arabic.txt")
End Using
IronOCR は複数言語の文書を処理できますか?
ドキュメントに混合言語が含まれている場合は、IronOCR を多言語サポート用に設定します。
Install-Package IronOcr.Languages.ChineseSimplified
// Multi-language OCR configuration
using IronOcr;
var ocr = new IronTesseract();
// Set primary language
ocr.Language = OcrLanguage.ChineseSimplified;
// Add secondary languages as needed
ocr.AddSecondaryLanguage(OcrLanguage.English);
// Custom .traineddata files can be added for specialized recognition
// ocr.AddSecondaryLanguage("path/to/custom.traineddata");
using (var input = new OcrInput())
{
// Process multi-language document
input.LoadImage("img/MultiLanguage.jpeg");
var result = ocr.Read(input);
result.SaveAsTextFile("MultiLanguage.txt");
}
// Multi-language OCR configuration
using IronOcr;
var ocr = new IronTesseract();
// Set primary language
ocr.Language = OcrLanguage.ChineseSimplified;
// Add secondary languages as needed
ocr.AddSecondaryLanguage(OcrLanguage.English);
// Custom .traineddata files can be added for specialized recognition
// ocr.AddSecondaryLanguage("path/to/custom.traineddata");
using (var input = new OcrInput())
{
// Process multi-language document
input.LoadImage("img/MultiLanguage.jpeg");
var result = ocr.Read(input);
result.SaveAsTextFile("MultiLanguage.txt");
}
Imports IronOcr
' Multi-language OCR configuration
Dim ocr As New IronTesseract()
' Set primary language
ocr.Language = OcrLanguage.ChineseSimplified
' Add secondary languages as needed
ocr.AddSecondaryLanguage(OcrLanguage.English)
' Custom .traineddata files can be added for specialized recognition
' ocr.AddSecondaryLanguage("path/to/custom.traineddata")
Using input As New OcrInput()
' Process multi-language document
input.LoadImage("img/MultiLanguage.jpeg")
Dim result = ocr.Read(input)
result.SaveAsTextFile("MultiLanguage.txt")
End Using
C# OCR を使用して複数ページのドキュメントを処理する方法
IronOCRは、複数のページや画像をシームレスに1つのOcrResultに結合します。 この機能により、検索可能な PDF の作成やドキュメント セット全体からのテキストの抽出などの強力な機能が可能になります。
1 回の OCR 操作で、画像、TIFF フレーム、PDF ページなど、さまざまなソースを組み合わせて使用できます。
// Multi-source document processing
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Add various image formats
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
// Process specific frames from multi-frame images
int[] frameNumbers = { 1, 2 };
input.LoadImageFrames("image3.gif", frameNumbers);
// Process all sources together
OcrResult result = ocr.Read(input);
// Verify page count
Console.WriteLine($"{result.Pages.Count} Pages processed.");
}
// Multi-source document processing
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Add various image formats
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
// Process specific frames from multi-frame images
int[] frameNumbers = { 1, 2 };
input.LoadImageFrames("image3.gif", frameNumbers);
// Process all sources together
OcrResult result = ocr.Read(input);
// Verify page count
Console.WriteLine($"{result.Pages.Count} Pages processed.");
}
Imports IronOcr
' Multi-source document processing
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Add various image formats
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
' Process specific frames from multi-frame images
Dim frameNumbers As Integer() = {1, 2}
input.LoadImageFrames("image3.gif", frameNumbers)
' Process all sources together
Dim result As OcrResult = ocr.Read(input)
' Verify page count
Console.WriteLine($"{result.Pages.Count} Pages processed.")
End Using
TIFF ファイルのすべてのページを効率的に処理します。
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Define pages to process (0-based indexing)
int[] pageIndices = new int[] { 0, 1 };
// Load specific TIFF frames
input.LoadImageFrames("MultiFrame.Tiff", pageIndices);
// Extract text from all frames
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
Console.WriteLine($"{result.Pages.Count} Pages processed");
}
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Define pages to process (0-based indexing)
int[] pageIndices = new int[] { 0, 1 };
// Load specific TIFF frames
input.LoadImageFrames("MultiFrame.Tiff", pageIndices);
// Extract text from all frames
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
Console.WriteLine($"{result.Pages.Count} Pages processed");
}
Imports IronOcr
Private ocr As New IronTesseract()
Using input As New OcrInput()
' Define pages to process (0-based indexing)
Dim pageIndices() As Integer = { 0, 1 }
' Load specific TIFF frames
input.LoadImageFrames("MultiFrame.Tiff", pageIndices)
' Extract text from all frames
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
Console.WriteLine($"{result.Pages.Count} Pages processed")
End Using
TIFF または PDF を検索可能な形式に変換します。
using System;
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Set document metadata
input.Title = "Quarterly Report";
// Combine multiple sources
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
// Add specific frames from animated images
int[] gifFrames = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", gifFrames);
// Create searchable PDF
OcrResult result = ocr.Read(input);
// Pass true to apply any active OcrInput filters to the searchable PDF output (added v2025.5.11)
result.SaveAsSearchablePdf("searchable.pdf", true);
}
using System;
using IronOcr;
IronTesseract ocr = new IronTesseract();
using (OcrInput input = new OcrInput())
{
// Set document metadata
input.Title = "Quarterly Report";
// Combine multiple sources
input.LoadImage("image1.jpeg");
input.LoadImage("image2.png");
// Add specific frames from animated images
int[] gifFrames = new int[] { 1, 2 };
input.LoadImageFrames("image3.gif", gifFrames);
// Create searchable PDF
OcrResult result = ocr.Read(input);
// Pass true to apply any active OcrInput filters to the searchable PDF output (added v2025.5.11)
result.SaveAsSearchablePdf("searchable.pdf", true);
}
Imports System
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Set document metadata
input.Title = "Quarterly Report"
' Combine multiple sources
input.LoadImage("image1.jpeg")
input.LoadImage("image2.png")
' Add specific frames from animated images
Dim gifFrames As Integer() = {1, 2}
input.LoadImageFrames("image3.gif", gifFrames)
' Create searchable PDF
Dim result As OcrResult = ocr.Read(input)
' Pass true to apply any active OcrInput filters to the searchable PDF output (added v2025.5.11)
result.SaveAsSearchablePdf("searchable.pdf", True)
End Using
既存の PDF を検索可能なバージョンに変換します。
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Set PDF metadata
input.Title = "Annual Report 2024";
// Process existing PDF
input.LoadPdf("example.pdf", "password");
// Generate searchable version
var result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Set PDF metadata
input.Title = "Annual Report 2024";
// Process existing PDF
input.LoadPdf("example.pdf", "password");
// Generate searchable version
var result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");
}
Imports IronOcr
Private ocr = New IronTesseract()
Using input = New OcrInput()
' Set PDF metadata
input.Title = "Annual Report 2024"
' Process existing PDF
input.LoadPdf("example.pdf", "password")
' Generate searchable version
Dim result = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")
End Using
同じ手法を TIFF 変換に適用します。
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Configure document properties
input.Title = "Scanned Archive Document";
// Select pages to process
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageIndices);
// Create searchable PDF from TIFF
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Configure document properties
input.Title = "Scanned Archive Document";
// Select pages to process
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageIndices);
// Create searchable PDF from TIFF
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable.pdf");
}
Imports IronOcr
Private ocr = New IronTesseract()
Using input = New OcrInput()
' Configure document properties
input.Title = "Scanned Archive Document"
' Select pages to process
Dim pageIndices = New Integer() { 1, 2 }
input.LoadImageFrames("example.tiff", pageIndices)
' Create searchable PDF from TIFF
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable.pdf")
End Using
OCR の結果を HOCR HTML としてエクスポートするにはどうすればいいですか?
IronOCR は HOCR HTML エクスポートをサポートしており、レイアウト情報を保持しながら構造化されたPDF から HTMLおよびTIFF から HTML への変換を可能にします。
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Set HTML title
input.Title = "Document Archive";
// Process multiple document types
input.LoadImage("image2.jpeg");
input.LoadPdf("example.pdf", "password");
// Add TIFF pages
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageIndices);
// Export as HOCR with position data
OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("hocr.html");
}
using IronOcr;
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Set HTML title
input.Title = "Document Archive";
// Process multiple document types
input.LoadImage("image2.jpeg");
input.LoadPdf("example.pdf", "password");
// Add TIFF pages
var pageIndices = new int[] { 1, 2 };
input.LoadImageFrames("example.tiff", pageIndices);
// Export as HOCR with position data
OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("hocr.html");
}
Imports IronOcr
Dim ocr As New IronTesseract()
Using input As New OcrInput()
' Set HTML title
input.Title = "Document Archive"
' Process multiple document types
input.LoadImage("image2.jpeg")
input.LoadPdf("example.pdf", "password")
' Add TIFF pages
Dim pageIndices As Integer() = {1, 2}
input.LoadImageFrames("example.tiff", pageIndices)
' Export as HOCR with position data
Dim result As OcrResult = ocr.Read(input)
result.SaveAsHocrFile("hocr.html")
End Using
IronOCR はテキストと一緒にバーコードも読み取ることができますか?
IronOCR はテキスト認識とバーコード読み取り機能を独自に組み合わせており、個別のライブラリを必要としません。
// Enable combined text and barcode recognition
using IronOcr;
var ocr = new IronTesseract();
// Enable barcode detection
ocr.Configuration.ReadBarCodes = true;
using (var input = new OcrInput())
{
// Load image containing both text and barcodes
input.LoadImage("img/Barcode.png");
// Process both text and barcodes
var result = ocr.Read(input);
// Extract barcode data
foreach (var barcode in result.Barcodes)
{
Console.WriteLine($"Barcode Value: {barcode.Value}");
Console.WriteLine($"Type: {barcode.Type}, Location: {barcode.Location}");
}
}
// Enable combined text and barcode recognition
using IronOcr;
var ocr = new IronTesseract();
// Enable barcode detection
ocr.Configuration.ReadBarCodes = true;
using (var input = new OcrInput())
{
// Load image containing both text and barcodes
input.LoadImage("img/Barcode.png");
// Process both text and barcodes
var result = ocr.Read(input);
// Extract barcode data
foreach (var barcode in result.Barcodes)
{
Console.WriteLine($"Barcode Value: {barcode.Value}");
Console.WriteLine($"Type: {barcode.Type}, Location: {barcode.Location}");
}
}
Imports IronOcr
Dim ocr As New IronTesseract()
' Enable barcode detection
ocr.Configuration.ReadBarCodes = True
Using input As New OcrInput()
' Load image containing both text and barcodes
input.LoadImage("img/Barcode.png")
' Process both text and barcodes
Dim result = ocr.Read(input)
' Extract barcode data
For Each barcode In result.Barcodes
Console.WriteLine($"Barcode Value: {barcode.Value}")
Console.WriteLine($"Type: {barcode.Type}, Location: {barcode.Location}")
Next
End Using
詳細な OCR 結果とメタデータにアクセスするにはどうすればよいでしょうか?
IronOCR 結果オブジェクトは、上級開発者が高度なアプリケーションに活用できる包括的なデータを提供します。
各 OcrResult には、ページ、段落、行、WORD、文字という階層的なコレクションが含まれています。 すべての要素には、場所、フォント情報、信頼スコアなどの詳細なメタデータが含まれます。
個々の要素 (段落、単語、バーコード) は、画像またはビットマップとしてエクスポートして、さらに処理することができます。
using System;
using IronOcr;
using IronSoftware.Drawing;
// Configure with barcode support
IronTesseract ocr = new IronTesseract
{
Configuration = { ReadBarCodes = true }
};
using OcrInput input = new OcrInput();
// Process multi-page document
int[] pageIndices = { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
OcrResult result = ocr.Read(input);
// Navigate the complete results hierarchy
foreach (var page in result.Pages)
{
// Page-level data
int pageNumber = page.PageNumber;
string pageText = page.Text;
int pageWordCount = page.WordCount;
// Extract page elements
OcrResult.Barcode[] barcodes = page.Barcodes;
AnyBitmap pageImage = page.ToBitmap();
double pageWidth = page.Width;
double pageHeight = page.Height;
foreach (var paragraph in page.Paragraphs)
{
// Paragraph properties
int paragraphNumber = paragraph.ParagraphNumber;
string paragraphText = paragraph.Text;
double paragraphConfidence = paragraph.Confidence;
var textDirection = paragraph.TextDirection;
foreach (var line in paragraph.Lines)
{
// Line details including baseline information
string lineText = line.Text;
double lineConfidence = line.Confidence;
double baselineAngle = line.BaselineAngle;
double baselineOffset = line.BaselineOffset;
foreach (var word in line.Words)
{
// Word-level data
string wordText = word.Text;
double wordConfidence = word.Confidence;
// Font information (when available)
if (word.Font != null)
{
string fontName = word.Font.FontName;
double fontSize = word.Font.FontSize;
bool isBold = word.Font.IsBold;
bool isItalic = word.Font.IsItalic;
}
foreach (var character in word.Characters)
{
// Character-level analysis
string charText = character.Text;
double charConfidence = character.Confidence;
// Alternative character choices for spell-checking
OcrResult.Choice[] alternatives = character.Choices;
}
}
}
}
}
using System;
using IronOcr;
using IronSoftware.Drawing;
// Configure with barcode support
IronTesseract ocr = new IronTesseract
{
Configuration = { ReadBarCodes = true }
};
using OcrInput input = new OcrInput();
// Process multi-page document
int[] pageIndices = { 1, 2 };
input.LoadImageFrames(@"img\Potter.tiff", pageIndices);
OcrResult result = ocr.Read(input);
// Navigate the complete results hierarchy
foreach (var page in result.Pages)
{
// Page-level data
int pageNumber = page.PageNumber;
string pageText = page.Text;
int pageWordCount = page.WordCount;
// Extract page elements
OcrResult.Barcode[] barcodes = page.Barcodes;
AnyBitmap pageImage = page.ToBitmap();
double pageWidth = page.Width;
double pageHeight = page.Height;
foreach (var paragraph in page.Paragraphs)
{
// Paragraph properties
int paragraphNumber = paragraph.ParagraphNumber;
string paragraphText = paragraph.Text;
double paragraphConfidence = paragraph.Confidence;
var textDirection = paragraph.TextDirection;
foreach (var line in paragraph.Lines)
{
// Line details including baseline information
string lineText = line.Text;
double lineConfidence = line.Confidence;
double baselineAngle = line.BaselineAngle;
double baselineOffset = line.BaselineOffset;
foreach (var word in line.Words)
{
// Word-level data
string wordText = word.Text;
double wordConfidence = word.Confidence;
// Font information (when available)
if (word.Font != null)
{
string fontName = word.Font.FontName;
double fontSize = word.Font.FontSize;
bool isBold = word.Font.IsBold;
bool isItalic = word.Font.IsItalic;
}
foreach (var character in word.Characters)
{
// Character-level analysis
string charText = character.Text;
double charConfidence = character.Confidence;
// Alternative character choices for spell-checking
OcrResult.Choice[] alternatives = character.Choices;
}
}
}
}
}
Imports System
Imports IronOcr
Imports IronSoftware.Drawing
' Configure with barcode support
Private ocr As New IronTesseract With {
.Configuration = { ReadBarCodes = True }
}
Private OcrInput As using
' Process multi-page document
Private pageIndices() As Integer = { 1, 2 }
input.LoadImageFrames("img\Potter.tiff", pageIndices)
Dim result As OcrResult = ocr.Read(input)
' Navigate the complete results hierarchy
For Each page In result.Pages
' Page-level data
Dim pageNumber As Integer = page.PageNumber
Dim pageText As String = page.Text
Dim pageWordCount As Integer = page.WordCount
' Extract page elements
Dim barcodes() As OcrResult.Barcode = page.Barcodes
Dim pageImage As AnyBitmap = page.ToBitmap()
Dim pageWidth As Double = page.Width
Dim pageHeight As Double = page.Height
For Each paragraph In page.Paragraphs
' Paragraph properties
Dim paragraphNumber As Integer = paragraph.ParagraphNumber
Dim paragraphText As String = paragraph.Text
Dim paragraphConfidence As Double = paragraph.Confidence
Dim textDirection = paragraph.TextDirection
For Each line In paragraph.Lines
' Line details including baseline information
Dim lineText As String = line.Text
Dim lineConfidence As Double = line.Confidence
Dim baselineAngle As Double = line.BaselineAngle
Dim baselineOffset As Double = line.BaselineOffset
For Each word In line.Words
' Word-level data
Dim wordText As String = word.Text
Dim wordConfidence As Double = word.Confidence
' Font information (when available)
If word.Font IsNot Nothing Then
Dim fontName As String = word.Font.FontName
Dim fontSize As Double = word.Font.FontSize
Dim isBold As Boolean = word.Font.IsBold
Dim isItalic As Boolean = word.Font.IsItalic
End If
For Each character In word.Characters
' Character-level analysis
Dim charText As String = character.Text
Dim charConfidence As Double = character.Confidence
' Alternative character choices for spell-checking
Dim alternatives() As OcrResult.Choice = character.Choices
Next character
Next word
Next line
Next paragraph
Next page
まとめ
IronOCR は、Windows、Linux、Mac プラットフォームでシームレスに実行される最も高度なTesseract API 実装を C# 開発者に提供します。 IronOCR を使用して、不完全なドキュメントからでも画像からテキストを正確に読み取ることができる機能は、基本的な OCR ソリューションとは一線を画しています。
ライブラリの独自の機能には、統合バーコード読み取り機能や、結果を検索可能な PDF または HOCR HTML としてエクスポートする機能などがあり、これらの機能は標準の Tesseract 実装では利用できません。
前進
IronOCR の習得を続けるには:
-包括的なスタートガイドをご覧ください -実用的なC#コード例を参照する -詳細なAPIドキュメントを参照してください
ソースコードのダウンロード
アプリケーションに C# OCR 画像からテキストへの変換を実装する準備はできていますか? 今すぐIronOCR をダウンロードして無料トライアルを開始してください。
よくある質問
Tesseract を使用せずに C# で画像をテキストに変換するにはどうすればよいですか?
IronOCR を使用して C# で画像をテキストに変換できます。IronOCR は、画像からテキストへの変換を直接処理する組み込みメソッドでこのプロセスを簡素化します。
低品質画像での OCR 精度を向上させるにはどうすればよいですか?
IronOCR には、Input.Deskew() および Input.DeNoise() などの画像フィルターが用意されており、傾きを補正し、ノイズを軽減することで低品質の画像を強化し、OCR の精度を大幅に向上させることができます。
C# で OCR を使用して複数ページのドキュメントからテキストを抽出する手順は何ですか?
複数ページのドキュメントからテキストを抽出するには、IronOCR を使用すると、LoadPdf() などのメソッドを使用して各ページをロードおよび処理し、各ページを効果的にテキストに変換できます。
画像からバーコードとテキストを同時に読み取ることは可能ですか?
はい、IronOCR は 1 つの画像からテキストとバーコードの両方を読み取ることができます。ocr.Configuration.ReadBarCodes = true を有効にすることで、テキストとバーコード データの両方を抽出できます。
複数の言語でドキュメントを処理するための OCR をセットアップするにはどうすればよいですか?
IronOCR は 125 を超える言語をサポートしており、ocr.Language コマンドを使用して主要な言語を設定し、ocr.AddSecondaryLanguage() コマンドを使用して追加言語を追加することで、多言語ドキュメントの処理を可能にします。
OCR 結果をさまざまな形式でエクスポートするために利用可能なメソッドは何ですか?
IronOCR は複数のメソッドを提供して OCR 結果をエクスポートできます。たとえば、PDF の場合は SaveAsSearchablePdf()、プレーンテキストの場合は SaveAsTextFile()、HOCR HTML 形式の場合は SaveAsHocrFile() があります。
大型画像ファイルの OCR 処理速度を最適化するにはどうすればよいですか?
OCR処理速度を最適化するには、IronOCR の OcrLanguage.EnglishFast を使用して高速な言語認識を実現し、System.Drawing.Rectangle を使用して 特定の領域を定義し、処理時間を短縮します。
保護されたPDFファイルのOCR処理をどのように扱うべきですか?
保護された PDF を処理する際は、正しいパスワードと共に LoadPdf() メソッドを使用します。IronOCR は、ページを画像に自動的に変換して、画像ベースの PDF を処理します。
OCR 結果が正確でない場合はどうすればよいですか?
OCR 結果が正確でない場合は、IronOCR の Input.Deskew() や Input.DeNoise() などの画像強化機能を使用し、正しい言語パックがインストールされていることを確認してください。
OCR プロセスをカスタマイズして特定の文字を除外することはできますか?
はい、IronOCR を利用して、BlackListCharacters プロパティを使用して特定の文字を除外することにより、精度とプロセス速度を改善し、関連するテキストにのみ焦点を当てるように OCR プロセスをカスタマイズできます。

