Click here to Skip to main content
15,792,771 members
Articles / Programming Languages / C#

Creating and Processing OMR Forms with LEADTOOLS

1 Aug 2013CPOL5 min read 38.5K   2.3K   8   4
Creating and Processing OMR Forms with LEADTOOLS

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Forms recognition and processing is used all over the world to tackle a wide variety of tasks including classification, document archival, optical character recognition and optical mark recognition. Out of those general categories, OMR is an oft misunderstood and underused feature in document imaging due to the time required to set up OMR based forms and the difficulty of accurately detecting which OMR fields are filled on a scanned document. Creating and processing OMR forms can be a time-consuming nightmare and this white paper will discuss how to alleviate those issues through automated detection, classification and processing.

Most forms contain a small number of OMR fields to capture information such as gender and marital status. These cause little to no difficulties because there are very few fields to deal with. On the other hand, creating and processing forms dominated by multiple choice questions is noticeably more difficult due to the sheer volume of fields that can be packed into a page. Additionally, the small size of check boxes, bubbles and other types of OMR fields creates potential hypersensitivity resulting in more false negatives or positives.

Below we will examine in more detail how to alleviate both of these common problems by developing an OMR forms recognition application with LEADTOOLS. This award-winning imaging SDK contains all the tools necessary to combine time-saving and programmer friendly APIs with state of the art recognition accuracy and speed for an unmatched level of quality in your final solution.

Using LEADTOOLS OCR to Add OMR Fields to a Master Form

The first step in a forms recognition application is to build the master forms. These master forms, or blank form templates, serve two primary purposes. First, it is used to identify what type of form a scanned document is. Second, the fields indicate the areas on the form from which data will be recognized and extracted.

For many systems, creating an OMR based form can be a tedious process due to the amount of repetition involved with surveys, bubble sheets or tests. One could spend hours manually drawing each and every OMR field around the boxes. Thankfully, LEADTOOLS is capable of automatically detecting all of the OMR fields with its IOcrEngine.AutoZone function. After finding each zone on the page, you can loop through the collection and add a new OMR field for each OMR zone.

 FormPages formPages = currentMasterForm.ReadFields();

// Create OCR Engine
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
   ocrEngine.Startup(null, null, null, null);
   ocrEngine.SettingManager.SetEnumValue("Recognition.Zoning.Options", "Detect Text, 
       Detect Graphics, Use Text Extractor, Detect Checkbox");
   using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
      // Auto zone
      ocrDocument.Pages.AddPages(rasterImageViewer1.Image, 1, 1, null);
      ocrDocument.Pages.AutoZone(OcrZoneParser.Leadtools, OcrZoneFillMethod.Omr, 
         LogicalUnit.Pixel, 0, 0, null);
      // Add a form field for each OMR zone
      FormField newField;
      IOcrZoneCollection zones = ocrDocument.Pages[0].Zones;
      for (int i = 0; i < zones.Count; i++)
         if (zones[i].FillMethod == OcrZoneFillMethod.Omr)
            newField = new OmrFormField();
            newField.Bounds = zones[i].Bounds;
            newField.Name = string.Format("OMR Field {0}", i);

Image 1

Figure 1: Master Forms Editor after OMR Field Detection

The OCR engine’s AutoZone method is used to get the location of each zone but there are many ways to go about naming them. This simple example gives a base name to the zones, but one could expand on this logic and name the zones more intelligently by checking the FormField.Bounds property to determine which zones are in the same row or column. Additionally, you can use the Master Forms Editor demo or manually edit the XML file in which the field data is stored.

Using LEADTOOLS Forms Recognition and Processing

Most scanned document processing systems must handle more than one type of form. A viable but inefficient solution might utilize a different application, button or dialog for each type of form that needs processing. This could certainly be implemented to automate the processing of data, but is handicapped by the requirement of manually informing the application which form template to process the scanned image with. An optimal solution is one in which the forms can be recognized or classified automatically and then processed based on those findings. LEADTOOLS provides reliable and flexible Forms Recognition capabilities with a variety of classification data including logos, dark and light areas, OCR, barcode and more.

// Create an OCR Engine for each processor on the machine. This
// allows for optimal use of thread during recognition and processing.
ocrEngines = new List<IOcrEngine>();
for (int i = 0; i < Environment.ProcessorCount; i++)
   ocrEngines.Add(OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false));
   ocrEngines[i].Startup(formsCodec, null, String.Empty, String.Empty);
// Point repository to directory with existing master forms
formsRepository = new DiskMasterFormsRepository(formsCodec, masterFormsFolder);
autoEngine = new AutoFormsEngine(formsRepository, ocrEngines, null, 
    AutoFormsRecognitionManager.Default | AutoFormsRecognitionManager.Ocr, 30, 80, true);
string[] formsToRecognize = Directory.GetFiles(filledFormsFolder);
progressBar1.Maximum = formsToRecognize.Length;
for (int i = 0; i < formsToRecognize.Length; i++)
   // Recognize (Classify) the form
   lblStatus.Text = string.Format("Recognizing form {0} of {1}", i + 1, 
   AutoFormsRunResult runResult = autoEngine.Run(formsToRecognize[i], null);
   if (runResult != null)
      // Recognition was successful
      lblStatus.Text = string.Format("Processing form {0} of {1}", i + 1, 

Extracting Answers from Completed OMR Forms

Once the form is recognized successfully, the fields can be processed to extract the OMR data from the filled out document. An important consideration when choosing an OMR solution is how accurately it can handle variances in fill styles. Even if strict rules are communicated to those filling out the forms, there will still be differences in how humans fill in the OMR fields. LEADTOOLS excels in its OMR accuracy and can distinguish between filled and unfilled boxes regardless of fill styles. For example, see the following screen captures of the same question from three filled surveys.

Image 2

Figure 2: Differences in How OMR Fields Are Filled

If you recall Figure 1, you can see the fields were named with the question number and column number separated by a hyphen. Armed with that naming paradigm we can then easily determine which checkbox was filled for each column and add it to our data source.

int nNewRowIndex = dataGridView1.Rows.Add();
foreach (FormPage formPage in runResult.FormFields)
   foreach (FormField field in formPage)
      if (field.Result.GetType() == typeof(OmrFormFieldResult))
         // Was this checkbox filled?
         if ((field.Result as OmrFormFieldResult).Text == "1")
            // Get the question number and value (column number) of this checkbox
            string[] strQuestionValue = field.Name.Split('-');
                strQuestionValue[0])].Value = strQuestionValue[1];

Image 3

Figure 3: Results from Completed Surveys

Naturally, there are many ways to name the fields and correlate the answers to your data source. With a little planning at the beginning stages of your application, you can design your OMR Forms recognition solution around any master form and data source for a dependable, flexible and most importantly, accurate solution using LEADTOOLS.

Download the Full Forms Recognition Example

You can download the fully functional demo which includes the features discussed above. To run this example you will need the following:


Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team ( or call us at 704-332-5532.


LEAD Technologies has been the prominent provider of digital imaging tools since 1990. Its award-winning LEADTOOLS family of toolkits helps developers integrate raster, document, medical, multimedia, vector and Internet imaging into their applications quickly and easily. Using LEADTOOLS for your imaging requirements allows you to spend more time on user interface and application-specific code, expediting your development cycle and increasing your return on investment.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Help desk / Support LEAD Technologies, Inc.
United States United States
Since 1990, LEAD has established itself as the world's leading provider of software development toolkits for document, medical, multimedia, raster and vector imaging. LEAD's flagship product, LEADTOOLS, holds the top position in every major country throughout the world and boasts a healthy, diverse customer base and strong list of corporate partners including some of the largest and most influential organizations from around the globe. For more information, contact or
This is a Organisation (No members)

Comments and Discussions

QuestionPrice For Full Package Pin
razrx31-Jul-17 15:10
razrx31-Jul-17 15:10 
AnswerRe: Price For Full Package Pin
LEADTOOLS Support19-Oct-17 7:24
sponsorLEADTOOLS Support19-Oct-17 7:24 
Both OMR and Forms Recognition are included in our LEADTOOLS Recognition Imaging SDK. You can find pricing details for development here
The page also includes information about deployment licensing. If you need additional pricing information, you can call the number on the page, use the live chat link from the same page or email
LEAD Technologies Inc.
LEADTOOLS Imaging SDK Home Page

QuestionLeadTools locked omr capabilities Pin
Member 1132856127-Dec-14 21:54
Member 1132856127-Dec-14 21:54 
AnswerRe: LeadTools locked omr capabilities Pin
LEADTOOLS Support30-Dec-14 7:08
sponsorLEADTOOLS Support30-Dec-14 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.