高速構成の主なコンポーネントは Language プロパティです。 Language プロパティを OcrLanguage.EnglishFast に設定することで、わずかに精度を犠牲にしつつ速度を優先します。 これにより、IronOCRはより迅速に一括して読むことができ、これは特に時間が重要なミッションクリティカルなアプリケーションで役立ちます。
/* :path=/static-assets/ocr/content-code-examples/how-to/ocr-fast-configuration.cs */using IronOcr;using System;var ocrTesseract = new IronTesseract();// Fast DictionaryocrTesseract.Language = OcrLanguage.EnglishFast;// Turn off unneeded optionsocrTesseract.Configuration.ReadBarCodes = false;// Assume text is laid out neatly in an orthogonal documentocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;using var ocrInput = new OcrInput();ocrInput.LoadImage("image.png");var ocrResult = ocrTesseract.Read(ocrInput);Console.WriteLine(ocrResult.Text);
/* :path=/static-assets/ocr/content-code-examples/how-to/ocr-fast-configuration.cs */
using IronOcr;
using System;
var ocrTesseract = new IronTesseract();
// Fast Dictionary
ocrTesseract.Language = OcrLanguage.EnglishFast;
// Turn off unneeded options
ocrTesseract.Configuration.ReadBarCodes = false;
// Assume text is laid out neatly in an orthogonal document
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
using var ocrInput = new OcrInput();
ocrInput.LoadImage("image.png");
var ocrResult = ocrTesseract.Read(ocrInput);
Console.WriteLine(ocrResult.Text);
using IronOcr;using System;using System.Diagnostics;using System.IO;// --- Tesseract Engine Setup ---var ocrTesseract = new IronTesseract();ocrTesseract.Language = OcrLanguage.EnglishFast;ocrTesseract.Configuration.ReadBarCodes = false;ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;// --- 1. Define folder and get files ---string folderPath = @"images"; // IMPORTANT: Set this to your image directorystring filePattern = "*.png"; // Change to "*.jpg", "*.bmp", etc. as neededstring outputFilePath = "ocr_results.txt"; // The new results file// Get all image files in the directoryvar imageFiles = Directory.GetFiles(folderPath, filePattern);Console.WriteLine($"Found {imageFiles.Length} total images to process...");Console.WriteLine($"Results will be written to: {outputFilePath}");// --- 2. Start timer and process images, writing to file ---// Open the output file *before* the loop for efficiencyusing (StreamWriter writer = new StreamWriter(outputFilePath)){ var stopwatch = Stopwatch.StartNew(); foreach (var file in imageFiles) { string fileName = Path.GetFileName(file); using var ocrInput = new OcrInput(); ocrInput.LoadImage(file); var ocrResult = ocrTesseract.Read(ocrInput); // Check if any text was actually found if (!string.IsNullOrEmpty(ocrResult.Text)) { // Write to ConsoleConsole.WriteLine($"--- Text found in: {fileName} ---");Console.WriteLine(ocrResult.Text.Trim());Console.WriteLine("------------------------------------------"); // Write to File writer.WriteLine($"--- Text found in: {fileName} ---"); writer.WriteLine(ocrResult.Text.Trim()); writer.WriteLine("------------------------------------------"); writer.WriteLine(); // Add a blank line for readability } else { // Write to ConsoleConsole.WriteLine($"No text found in: {fileName}"); // Write to File writer.WriteLine($"No text found in: {fileName}"); writer.WriteLine(); } } stopwatch.Stop(); // --- 3. Print and write final benchmark summary --- string lineSeparator = "\n========================================"; string title = "Batch OCR Processing Complete"; string summary = $"Fast configuration took {stopwatch.Elapsed.TotalSeconds:F2} seconds"; // Write summary to ConsoleConsole.WriteLine(lineSeparator);Console.WriteLine(title);Console.WriteLine("========================================");Console.WriteLine(summary); // Write summary to File writer.WriteLine(lineSeparator); writer.WriteLine(title); writer.WriteLine("========================================"); writer.WriteLine(summary); if (imageFiles.Length > 0) { string avgTime = $"Average time per image: {(stopwatch.Elapsed.TotalSeconds / (double)imageFiles.Length):F3} seconds";Console.WriteLine(avgTime); writer.WriteLine(avgTime); }}Console.WriteLine($"\nSuccessfully saved results to {outputFilePath}");
using IronOcr;
using System;
using System.Diagnostics;
using System.IO;
// --- Tesseract Engine Setup ---
var ocrTesseract = new IronTesseract();
ocrTesseract.Language = OcrLanguage.EnglishFast;
ocrTesseract.Configuration.ReadBarCodes = false;
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto;
// --- 1. Define folder and get files ---
string folderPath = @"images"; // IMPORTANT: Set this to your image directory
string filePattern = "*.png"; // Change to "*.jpg", "*.bmp", etc. as needed
string outputFilePath = "ocr_results.txt"; // The new results file
// Get all image files in the directory
var imageFiles = Directory.GetFiles(folderPath, filePattern);
Console.WriteLine($"Found {imageFiles.Length} total images to process...");
Console.WriteLine($"Results will be written to: {outputFilePath}");
// --- 2. Start timer and process images, writing to file ---
// Open the output file *before* the loop for efficiency
using (StreamWriter writer = new StreamWriter(outputFilePath))
{
var stopwatch = Stopwatch.StartNew();
foreach (var file in imageFiles)
{
string fileName = Path.GetFileName(file);
using var ocrInput = new OcrInput();
ocrInput.LoadImage(file);
var ocrResult = ocrTesseract.Read(ocrInput);
// Check if any text was actually found
if (!string.IsNullOrEmpty(ocrResult.Text))
{
// Write to Console
Console.WriteLine($"--- Text found in: {fileName} ---");
Console.WriteLine(ocrResult.Text.Trim());
Console.WriteLine("------------------------------------------");
// Write to File
writer.WriteLine($"--- Text found in: {fileName} ---");
writer.WriteLine(ocrResult.Text.Trim());
writer.WriteLine("------------------------------------------");
writer.WriteLine(); // Add a blank line for readability
}
else
{
// Write to Console
Console.WriteLine($"No text found in: {fileName}");
// Write to File
writer.WriteLine($"No text found in: {fileName}");
writer.WriteLine();
}
}
stopwatch.Stop();
// --- 3. Print and write final benchmark summary ---
string lineSeparator = "\n========================================";
string title = "Batch OCR Processing Complete";
string summary = $"Fast configuration took {stopwatch.Elapsed.TotalSeconds:F2} seconds";
// Write summary to Console
Console.WriteLine(lineSeparator);
Console.WriteLine(title);
Console.WriteLine("========================================");
Console.WriteLine(summary);
// Write summary to File
writer.WriteLine(lineSeparator);
writer.WriteLine(title);
writer.WriteLine("========================================");
writer.WriteLine(summary);
if (imageFiles.Length > 0)
{
string avgTime = $"Average time per image: {(stopwatch.Elapsed.TotalSeconds / (double)imageFiles.Length):F3} seconds";
Console.WriteLine(avgTime);
writer.WriteLine(avgTime);
}
}
Console.WriteLine($"\nSuccessfully saved results to {outputFilePath}");
ImportsIronOcrImportsSystemImportsSystem.DiagnosticsImportsSystem.IO' --- Tesseract Engine Setup ---Dim ocrTesseract As New IronTesseract()ocrTesseract.Language = OcrLanguage.EnglishFastocrTesseract.Configuration.ReadBarCodes = FalseocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto' --- 1. Define folder and get files ---Dim folderPath AsString = "images" ' IMPORTANT: Set this to your image directoryDim filePattern AsString = "*.png" ' Change to "*.jpg", "*.bmp", etc. as neededDim outputFilePath AsString = "ocr_results.txt" ' The new results file' Get all image files in the directoryDim imageFiles = Directory.GetFiles(folderPath, filePattern)Console.WriteLine($"Found {imageFiles.Length} total images to process...")Console.WriteLine($"Results will be written to: {outputFilePath}")' --- 2. Start timer and process images, writing to file ---' Open the output file *before* the loop for efficiencyUsing writer As New StreamWriter(outputFilePath) Dim stopwatch = Stopwatch.StartNew() For Each file In imageFiles Dim fileName AsString = Path.GetFileName(file)Using ocrInput As New OcrInput() ocrInput.LoadImage(file) Dim ocrResult = ocrTesseract.Read(ocrInput) ' Check if any text was actually found IfNotString.IsNullOrEmpty(ocrResult.Text) Then ' Write to ConsoleConsole.WriteLine($"--- Text found in: {fileName} ---")Console.WriteLine(ocrResult.Text.Trim())Console.WriteLine("------------------------------------------") ' Write to File writer.WriteLine($"--- Text found in: {fileName} ---") writer.WriteLine(ocrResult.Text.Trim()) writer.WriteLine("------------------------------------------") writer.WriteLine() ' Add a blank line for readability Else ' Write to ConsoleConsole.WriteLine($"No text found in: {fileName}") ' Write to File writer.WriteLine($"No text found in: {fileName}") writer.WriteLine() End IfEndUsing Next stopwatch.Stop() ' --- 3. Print and write final benchmark summary --- Dim lineSeparator AsString = vbLf & "========================================" Dim title AsString = "Batch OCR Processing Complete" Dim summary AsString = $"Fast configuration took {stopwatch.Elapsed.TotalSeconds:F2} seconds" ' Write summary to ConsoleConsole.WriteLine(lineSeparator)Console.WriteLine(title)Console.WriteLine("========================================")Console.WriteLine(summary) ' Write summary to File writer.WriteLine(lineSeparator) writer.WriteLine(title) writer.WriteLine("========================================") writer.WriteLine(summary) If imageFiles.Length > 0 Then Dim avgTime AsString = $"Average time per image: {(stopwatch.Elapsed.TotalSeconds / CDbl(imageFiles.Length)):F3} seconds"Console.WriteLine(avgTime) writer.WriteLine(avgTime) End IfEndUsingConsole.WriteLine(vbLf & $"Successfully saved results to {outputFilePath}")
Imports IronOcr
Imports System
Imports System.Diagnostics
Imports System.IO
' --- Tesseract Engine Setup ---
Dim ocrTesseract As New IronTesseract()
ocrTesseract.Language = OcrLanguage.EnglishFast
ocrTesseract.Configuration.ReadBarCodes = False
ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto
' --- 1. Define folder and get files ---
Dim folderPath As String = "images" ' IMPORTANT: Set this to your image directory
Dim filePattern As String = "*.png" ' Change to "*.jpg", "*.bmp", etc. as needed
Dim outputFilePath As String = "ocr_results.txt" ' The new results file
' Get all image files in the directory
Dim imageFiles = Directory.GetFiles(folderPath, filePattern)
Console.WriteLine($"Found {imageFiles.Length} total images to process...")
Console.WriteLine($"Results will be written to: {outputFilePath}")
' --- 2. Start timer and process images, writing to file ---
' Open the output file *before* the loop for efficiency
Using writer As New StreamWriter(outputFilePath)
Dim stopwatch = Stopwatch.StartNew()
For Each file In imageFiles
Dim fileName As String = Path.GetFileName(file)
Using ocrInput As New OcrInput()
ocrInput.LoadImage(file)
Dim ocrResult = ocrTesseract.Read(ocrInput)
' Check if any text was actually found
If Not String.IsNullOrEmpty(ocrResult.Text) Then
' Write to Console
Console.WriteLine($"--- Text found in: {fileName} ---")
Console.WriteLine(ocrResult.Text.Trim())
Console.WriteLine("------------------------------------------")
' Write to File
writer.WriteLine($"--- Text found in: {fileName} ---")
writer.WriteLine(ocrResult.Text.Trim())
writer.WriteLine("------------------------------------------")
writer.WriteLine() ' Add a blank line for readability
Else
' Write to Console
Console.WriteLine($"No text found in: {fileName}")
' Write to File
writer.WriteLine($"No text found in: {fileName}")
writer.WriteLine()
End If
End Using
Next
stopwatch.Stop()
' --- 3. Print and write final benchmark summary ---
Dim lineSeparator As String = vbLf & "========================================"
Dim title As String = "Batch OCR Processing Complete"
Dim summary As String = $"Fast configuration took {stopwatch.Elapsed.TotalSeconds:F2} seconds"
' Write summary to Console
Console.WriteLine(lineSeparator)
Console.WriteLine(title)
Console.WriteLine("========================================")
Console.WriteLine(summary)
' Write summary to File
writer.WriteLine(lineSeparator)
writer.WriteLine(title)
writer.WriteLine("========================================")
writer.WriteLine(summary)
If imageFiles.Length > 0 Then
Dim avgTime As String = $"Average time per image: {(stopwatch.Elapsed.TotalSeconds / CDbl(imageFiles.Length)):F3} seconds"
Console.WriteLine(avgTime)
writer.WriteLine(avgTime)
End If
End Using
Console.WriteLine(vbLf & $"Successfully saved results to {outputFilePath}")
Can IronOCR's fast configuration handle batch processing efficiently?
Yes, IronOCR's fast configuration is designed for efficient batch processing, allowing multiple images to be processed in a single operation with enhanced speed due to reduced computational load per image.
How does benchmark testing demonstrate the performance of fast configuration?
Benchmark testing with a set of sample images revealed that fast configuration can process images 17% quicker than the standard mode, demonstrating its superior speed without compromising text output accuracy.
When should the standard OCR configuration be preferred over fast configuration?
The standard OCR configuration should be used in scenarios requiring high accuracy, such as processing low-quality scans, recognizing multiple languages, or handling specialized documents like passports or license plates.
Is it easy to switch between fast and standard configurations in IronOCR?
Yes, IronOCR allows easy switching between configurations by changing a few properties, enabling swift adaptation to varying performance needs without complex code adjustments.