Optical mark recognition (OMR)

To recognize a filled questionnaire, answer sheet, ballot, or other OMR form, digitize it in one of the supported formats. For best results, we recommend using a scanner (a basic office scanner or multifunction copier will suffice). If you do not have a scanner, you can simply take a picture of the form with any modern smartphone and upload the photo to your computer.

Initializing the recognition engine

Aspose.OMR recognition engine is initialized with the recognition pattern (a file with .OMR extension), generated along with the printable form. The recognition pattern is loaded using GetTemplateProcessor method of Aspose.OMR.Api.OmrEngine class:

Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor("pattern.omr");

You can also load the recognition pattern as a MemoryStream object, which can be very useful when building web applications or APIs:

byte[] pattern = Encoding.UTF8.GetBytes(payload);
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = null;
using(MemoryStream ms = new MemoryStream(pattern))
{
	templateProcessor = omrEngine.GetTemplateProcessor(ms, Encoding.UTF8);
}

Recovering a recognition pattern file

If you have lost the recognition pattern file for the survey, simply generate it again from the form source code using exactly the same paper size, orientation, font, and other layout setting.

Completed form sources

Aspose.OCR for .NET can recognize completed interactive machine-readable PDF forms along with scanned or photographed hand-filled forms. You can provide a mix of scanned and interactive forms and get the identical recognition results regardless of the source file type.

If Aspose.OCR for .NET detects at least one interactive element (such as a checkbox or input field) in the provided PDF, it classifies the PDF as interactive and reads the built-in form elements to retrieve results. If no interactive elements are found, the form is treated as a scanned document, and filled-in elements are identified using optical mark recognition algorithms. Barcodes and QR codes are always treated as images, regardless of the PDF type.

Recognizing OMR form from a single respondent

To recognize a completed form, process its scan or photo through Recognize method of the initialized recognition engine. You can supply a form as:

  • An absolute or relative path to the image (for single-page forms).
  • An absolute or relative path to the scanned PDF (for single-page or multi-page forms).
  • An absolute or relative path to the interactive PDF (for single-page or multi-page forms).
  • A memory stream containing a scan or a photo of the form in any of the supported formats. Useful for building web applications or APIs.
  • An array of paths to scanned form pages (for multi-page forms).
  • An array of memory streams containing scans or photographs of the completed form pages in any of the supported formats. Useful for building web applications or APIs.

Regardless of the completed form format, the recognition method supports accuracy adjustments for reliable results under various conditions.

Bulk recognition

The whole idea behind OMR is to automatically process hundreds of forms. Aspose.OMR for .NET greatly simplifies this task by allowing you to recognize a directory with form images using a single method rather than recognizing files one by one:

Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor("pattern.omr");
Aspose.OMR.Model.RecognitionResult recognitionResults[] = templateProcessor.RecognizeFolder(@"C:\final_exam\");

Handling recognition errors

Aspose.OMR API can automatically validate the completed forms and throw an exception when the form is filled incorrectly. For example, when more than one answer is provided for a question that can only accept a single answer. This can be very useful when handling strict forms, such as:

  • Quizzes
  • Exam sheets
  • Voting ballots
  • Application forms

To validate the forms, set an additional parameter in the GetTemplateProcessor method to FormValidationLogic.Exception and catch Aspose.OMR.MultiselectException upon form recognition.

OmrEngine engine = new OmrEngine();
TemplateProcessor templateProcessor = engine.GetTemplateProcessor(templatePath, FormValidationLogic.Exception);
try
{
	RecognitionResult result = templateProcessor.Recognize("scan.png");
}
catch (MultiselectException ex)
{
	Console.WriteLine("The student filled the form incorrectly!");
}

Saving recognition results

Recognition results are returned in the most popular data storage formats that can be imported into any popular database or analysis system: CSV, XML or JSON. See more information in the dedicated article.

Interactive adjustments and debugging

You can use the graphical user interface control bundled with Aspose.OMR for .NET package to interactively fine tuning recognition accuracy before batch processing a large number of scanned forms or for investigating recognition problems.