Perform OMR and Extract Data using C#

Perform OMR and Extract Data using C#

Optical mark recognition (OMR) allows the reading and capturing of data marked on a special type of document form. This document form could be a test or a survey, consisting of bubble or square inputs filled by users. We can easily perform OMR operations on the scanned images of such survey forms or test sheets and read the user inputs programmatically in .NET applications. In this article, we will learn how to perform OMR and extract data using C#.

The following topics shall be covered in this article:

C# OMR API to Perform OMR and Extract Data

For performing OMR operations and exporting data from images, we will be using the Aspose.OMR for .NET API. It allows designing, creating, and recognizing answer sheets, tests, MCQ papers, quizzes, feedback forms, surveys, and ballots. Please either download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.OMR

Perform OMR and Extract Data from Image

In order to perform OMR operation on an image, we need the prepared OMR template (.omr) and the image (user-filled forms/sheets) to perform OMR on. We can perform an OMR operation on an image and extract data by following the steps given below:

  1. Firstly, create an instance of the OmrEngine class.
  2. Next, call the GetTemplateProcessor() method and initialize TemplateProcessor class object. It takes the OMR template file path as an argument.
  3. Then, get the RecognitionResult object by calling the RecognizeImage() method with the image path as an argument.
  4. After that, get recognition results as CSV strings using the GetCsv() method.
  5. Finally, save the CSV result as a CSV file on the local disk.

The following code sample shows how to perform OMR on an image and extract data in CSV format using C#.

Perform OMR and Extract Data from Images
Perform OMR and Extract Data from images.

The OMR template used in the above code example can be downloaded from here.

Perform OMR and Extract Data from Multiple Images

We can perform OMR operations on multiple images and extract data in a separate CSV file for each image by following the steps mentioned earlier. However, we need to repeat steps # 3, 4, and 5 for all the images one by one.

The following code sample shows how to perform OMR on multiple images and extract data in CSV format using C#.

The API also provides functionality to detect and recognize any barcodes available on the image during OMR operation. It is the default feature of the OMR operation. We can perform OMR operations and recognize barcodes by following the steps mentioned earlier.

Get OMR Results with Threshold

We can apply the threshold while performing OMR operations on images. The value of the threshold could be from 0 to 100 depending on the requirements. The higher the value of the threshold, the API becomes more strict regarding highlight the answers. Please follow the steps mentioned earlier to perform OMR with the threshold. However, we just need to call the overloaded RecognizeImage(string, int32) method in step # 3. It takes the image file path and the threshold value as arguments.

The following code sample shows how to perform OMR with threshold value using C#.

OMR Operation with Recalculation

In certain cases, we may need to recalculate the OMR results with different threshold values. For this purpose, we can configure the API to automatically recalculate using TemplateProcessor.recalculate() method. It allows processing an image multiple times by changing the threshold setting to get the desired result. We can perform OMR operation with recalculation by following the steps given below:

  1. Firstly, create an instance of the OmrEngine class.
  2. Next, call the GetTemplateProcessor() method and initialize TemplateProcessor class object. It takes the OMR template file path as an argument.
  3. Then, initialize the Stopwatch object and start the timer.
  4. Next, get the RecognitionResult object by calling the RecognizeImage() method with the image path as an argument.
  5. Then, stop the timer and export recognition results as a CSV string using the GetCsv() method.
  6. Next, save the CSV result as a CSV file on the local disk.
  7. Then, restart the timer using the Restart() method.
  8. Next, call the Recalculate() method. It takes the RecognitionResult object and the threshold value as arguments.
  9. After that, stop the timer and export recognition results as a CSV string using the GetCsv() method.
  10. Finally, save the CSV result as a CSV file on the local disk.

The following code sample shows how to perform OMR with the recalculation method using C#.

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to:

  • perform OMR operation on images and extract data in CSV format using C#;
  • apply threshold setting while performing OMR on images;
  • recalculate OMR results in an automotive process programmatically.

Besides, you can learn more about Aspose.OMR for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also