Filter Wizard
IronOCR includes an OcrInputFilterWizard
class that can automatically evaluate combinations of preprocessing filters to maximize OCR confidence. This is ideal when you're unsure which filters yield the best results. Instead of manually applying contrast, sharpen, binarize, etc., OcrInputFilterWizard.Run(...)
performs a brute-force scan for optimal settings and returns the best filter combination or code snippet to reproduce it.
Below is an example of how you might work with the OcrInputFilterWizard
. The code demonstrates retrieving and applying the suitable filters for an image preprocessing task relevant to Optical Character Recognition (OCR).
using IronOcr;
using System;
// Initialize OCR engine
var ocr = new IronTesseract();
// The path to the source image
string imagePath = @"input_image.png";
// Run the filter wizard to discover the best combination:
// Returns code snippet and outputs best OCR confidence result
double bestConfidence;
string bestCode = OcrInputFilterWizard.Run(
imagePath,
out bestConfidence,
ocr
);
Console.WriteLine($"Highest OCR confidence: {bestConfidence:P}");
Console.WriteLine("Code to replicate filters:");
Console.WriteLine(bestCode);
// Optionally, apply the recommended filters manually using OcrInput
using var input = new OcrInput();
input.AddImage(imagePath);
// Example: you might parse bestCode and apply suggested filters
// e.g. input.Contrast(), input.Sharpen(), input.Binarize(), etc.
// Run OCR with improved filters (if coded manually)
var result = ocr.Read(input);
Console.WriteLine("OCR Text:");
Console.WriteLine(result.Text);
using IronOcr;
using System;
// Initialize OCR engine
var ocr = new IronTesseract();
// The path to the source image
string imagePath = @"input_image.png";
// Run the filter wizard to discover the best combination:
// Returns code snippet and outputs best OCR confidence result
double bestConfidence;
string bestCode = OcrInputFilterWizard.Run(
imagePath,
out bestConfidence,
ocr
);
Console.WriteLine($"Highest OCR confidence: {bestConfidence:P}");
Console.WriteLine("Code to replicate filters:");
Console.WriteLine(bestCode);
// Optionally, apply the recommended filters manually using OcrInput
using var input = new OcrInput();
input.AddImage(imagePath);
// Example: you might parse bestCode and apply suggested filters
// e.g. input.Contrast(), input.Sharpen(), input.Binarize(), etc.
// Run OCR with improved filters (if coded manually)
var result = ocr.Read(input);
Console.WriteLine("OCR Text:");
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
' Initialize OCR engine
Private ocr = New IronTesseract()
' The path to the source image
Private imagePath As String = "input_image.png"
' Run the filter wizard to discover the best combination:
' Returns code snippet and outputs best OCR confidence result
Private bestConfidence As Double
Private bestCode As String = OcrInputFilterWizard.Run(imagePath, bestConfidence, ocr)
Console.WriteLine($"Highest OCR confidence: {bestConfidence:P}")
Console.WriteLine("Code to replicate filters:")
Console.WriteLine(bestCode)
' Optionally, apply the recommended filters manually using OcrInput
Dim input = New OcrInput()
input.AddImage(imagePath)
' Example: you might parse bestCode and apply suggested filters
' e.g. input.Contrast(), input.Sharpen(), input.Binarize(), etc.
' Run OCR with improved filters (if coded manually)
Dim result = ocr.Read(input)
Console.WriteLine("OCR Text:")
Console.WriteLine(result.Text)
Explanation
- Wizard Invocation
InvokesOcrInputFilterWizard.Run(imagePath, out bestConfidence, ocr)
to automatically test filter combinations and yield the best outcome (text read, confidence score, and code snippet to replicate) - No Manual Filter Loop
No need to loop through a list of functions—IronOCR handles it all and provides a script for reproduction. - Applying Filters via OcrInput
If you want to manually apply filters, you do so by calling methods onOcrInput
, e.g.input.Contrast()
,input.Sharpen()
,input.Binarize()
,input.Deskew()
, etc., which are supported by IronOCR’s filter API ironsoftware.com+11ironsoftware.com+11ironsoftware.com+11. - OCR Execution Use
IronTesseract.Read(input)
on the preprocessedOcrInput
.
Optional Filters You Can Apply
Some common filters in IronOCR that you might replicate manually include:
input.Contrast()
input.Sharpen()
input.Binarize()
input.ToGrayScale()
input.Invert()
input.Deskew()
input.Scale(...)
input.Denoise()
input.DeepCleanBackgroundNoise()
input.EnhanceResolution()
input.Dilate()
,input.Erode()
These methods may be used in combination when manually constructing pipelines, following guidance from the wizard results or your own testing.