Home > Code > C# > How to Apply Correction Filters before Document Recognition inside .NET Apps

How to Apply Correction Filters before Document Recognition inside .NET Apps

by sher azam   on Feb 11, 2015   Category: C#   |  Views: 698    |  Points: 25   |  Gold 

This technical tip shows how to improve recognition accuracy by applying correction filters before document recognition. In image recognition, we often need to perform some kind of noise reduction corrections on an image. Such noise reduction is a typical pre-processing step to improve the results of later processing. Using Aspose.OCR we can apply the following correction filters for improving recognition accuracy:

• Blur - applies a simple blur to the image.
• Gaussian blur - applies a Gaussian blur with a default radius of 3 pixels.
• Median - applies a median filter with a 3 pixel radius, by default. Median filters are good at keeping edges while removing noise.
• Noise removal - applies noise removal filter.

Note: Laguages other than English also requires loading the language specific resource using the LanguageFactory.Load method and adding it to the LanguageContainer using the AddLanguage method.

The sample code below shows how to use a correction filter before running the document recognition process.

//[C# Code Sample]

//Initialize an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();

//Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(imageFile);

//Create CorrectionFilters collection
CorrectionFilters filters = new CorrectionFilters();
Filter filter = null;

//Initialize Median filter
filter = new MedianFilter(5);

//Create Gaussian Blur filter
filter = new GaussBlurFilter();

//Create Noise Removal filter
filter = new RemoveNoiseFilter();

//Assign collection to OcrEngine
ocrEngine.Config.CorrectionFilters = filters;

//Run recognition process
if (ocrEngine.Process())
//Display results

//[VB.NET Code Sample]

'Initialize an instance of OcrEngine
Dim ocrEngine As New OcrEngine()

'Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(imageFile)

'Create CorrectionFilters collection
Dim filters As New CorrectionFilters()
Dim filter As Filter = Nothing

'Initialize Median filter
filter = New MedianFilter(5)

'Create Gaussian Blur filter
filter = New GaussBlurFilter()

'Create Noise Removal filter
filter = New RemoveNoiseFilter()

'Assign collection to OcrEngine
ocrEngine.Config.CorrectionFilters = filters

'Run recognition process
If ocrEngine.Process() Then
'Display results
End If

Overview: Aspose.OCR for .NET

Aspose.OCR for .NET is a character recognition component built to allow developers to add OCR functionality in their ASP .NET web applications, web services and Windows applications. It provides a simple set of classes for controlling character recognition tasks. It helps developers to work with image (BMP, TIFF) files from within their own applications. It allows developers to extract text from images quickly & easily, saving time & effort involved in developing an OCR solution from scratch.

- Homepage of Aspose.OCR for .NET: http://www.aspose.com/.net/ocr-component.aspx

-Download Aspose.OCR for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.ocr_for_.net/default.aspx

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts