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.
Recognizing OMR forms
To recognize a filled form page, process its scan or photo with the initialized recognition engine using RecognizeImage
method of the Aspose.OMR.Api.TemplateProcessor
class:
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor("pattern.omr");
Aspose.OMR.Model.RecognitionResult recognitionResult = templateProcessor.RecognizeImage("form-20220519.png");
You can also provide a form image as a MemoryStream
object, which can be very useful when building web applications or APIs:
// Load recognition pattern and form image
byte[] pattern = Encoding.UTF8.GetBytes(payload[0]);
byte[] form = Encoding.UTF8.GetBytes(payload[1]);
// Initialize recognition engine
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = null;
using(MemoryStream patternStream = new MemoryStream(pattern))
{
templateProcessor = omrEngine.GetTemplateProcessor(patternStream, Encoding.UTF8);
}
// Recognize
Aspose.OMR.Model.RecognitionResult recognitionResult = null;
using(MemoryStream formStream = new MemoryStream(form))
{
recognitionResult = templateProcessor.RecognizeImage(formStream);
}
Batch 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\");
Recognizing multi-page forms
If a form consists of several pages, use RecognizeMultiPageTemplate
method to recognize them as a single entity:
string[] formPages = { "page1.png", "page2.png", "page3.png" };
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Api.TemplateProcessor templateProcessor = omrEngine.GetTemplateProcessor("pattern.omr");
Aspose.OMR.Model.RecognitionResult recognitionResult[] = templateProcessor.RecognizeMultiPageTemplate(formPages);
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.