Home > Code > C# > How to Extract OMR Data from a Scanned Image Using C# & VB.NET

How to Extract OMR Data from a Scanned Image Using C# & VB.NET

by sher azam   on Jun 03, 2015   Category: C#   |  Views: 3329    |  Points: 25   |  Gold 

This technical tip shows how to extract OMR data from a scanned image inside .NET Applications. Developers can use the Aspose.OMR namespace to extract data entered into OMR (Optical Mark Recognition) forms, such as consumer surveys, assessment sheets, or lottery tickets. This article describes how to extract data from a scanned page using a OMR template created with OMR Template Editor tool. The Aspose.Omr namespace can be used to recognize and extract different elements from a scanned image. A template is required that contains graphical mapping of elements to be recognized from the scanned images. This template document is loaded using OmrTemplate. Pages with human marked data like surveys or tests are scanned, and the images loaded using the OmrImage class. A recognition engine (OmrEngine) is required for the template and can be initiated by using the current template as an argument. After the template has been set in the engine, the data is extracted from the scanned image using the OmrEngine class' ExtractData function. Below are the steps to extract OMR data from a scanned image:

• Load the template using OmrTemplate.
• Load the scanned image into OmrImage.
• Instantiate the recognition engine: OmrEngine for the template.
• Extract data and save to OmrProcessingResult.

The sample code below shows how to extract OMR data from a scanned image


//Load template file
OmrTemplate template = OmrTemplate.Load(MyDir + "Grids.amr");

//Load the image to be analyzed
OmrImage image = OmrImage.Load(MyDir + "Grids-filled-scan.jpg");

// Instantiate the recognition engine for the template
OmrEngine engine = new OmrEngine(template);

// Extract data. This template has only one page.
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });

//Load actual result from
Hashtable OmrResult = result.PageData[0];

//Get Collection of Keys
ICollection key = OmrResult.Keys;

foreach (string k in key)
Console.WriteLine(k + ": " + OmrResult[k]);


'Load template file
Dim template As OmrTemplate = OmrTemplate.Load(myDir + "Grids.amr")

'Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(MyDir + "Grids-filled-scan.jpg")

'Instantiate the recognition engine for the template
Dim engine As OmrEngine = New OmrEngine(template)

'Extract data. This template has only one page.
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})

'Load actual result from
Dim OmrResult As Hashtable = result.PageData(0)

'Get collection of keys
Dim Key As ICollection = OmrResult.Keys

For Each k As String In Key
Console.WriteLine(k + ": " + OmrResult(Key))

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