Starting with version 9.0 DotImage released a new add-on to perform forms processing and OMR (Optical Mark Recognition). This article will guide you through the steps of making an OMR application using our libraries.
Template Creation
OmrTemplateDocument Creation
The first step to be able to recognize marks on a form is to create a template file. Typically, using the cleanest possible blank form image is optimum for creating a template. In the following code snippet a single page OmrTemplateDocument object will be created and saved off to disk for later usage:
C#
internal static void BuildTemplate(string FileName, string OutFileName)
{
OmrTemplateDocument doc = new OmrTemplateDocument();
OmrTemplatePage page = MakePage(new AtalaImage(FileName));
doc.Pages.Add(page);
SaveFileDialog save = new SaveFileDialog();
save.ShowDialog();
using (Stream s = save.OpenFile())
{
doc.Save(s);
}
}
VB.NET
Friend Shared Sub BuildTemplate(FileName As String, OutFileName As String)
Dim doc As New OmrTemplateDocument()
Dim page As OmrTemplatePage = MakePage(New AtalaImage(FileName))
doc.Pages.Add(page)
Dim save As New SaveFileDialog()
save.ShowDialog()
Using s As Stream = save.OpenFile()
doc.Save(s)
End Using
End Sub
OmrTemplatePage Creation
Each OmrTemplatePage object is made up of an AtalaImage and any number of groups which in turn have any number of marks. Marks are defined in pixel space of the AtalaImage provided to create the OmrTemplatePage. In the example below a single mark area will be checked for marks at the coordinates (595,590) with a size of (50,50).
C#
private static OmrTemplatePage MakePage(AtalaImage img)
{
OmrTemplatePage page = new OmrTemplatePage(img);
OmrTemplateGroup group = new OmrTemplateGroup("Group 1");
group.Marks.Add(new OmrTemplateMark("Mark 1", new System.Drawing.Rectangle(595,590,50,50)));
page.Groups.Add(group);
return page;
}
VB.NET
Private Shared Function MakePage(img As AtalaImage) As OmrTemplatePage
Dim page As New OmrTemplatePage(img)
Dim group As New OmrTemplateGroup("Group 1")
group.Marks.Add(New OmrTemplateMark("Mark 1", New System.Drawing.Rectangle(595, 590, 50, 50)))
page.Groups.Add(group)
Return page
End Function
OmrEngineProcessing
Once there is a OmrTemplateDocument saved to disk, the engine is ready to be configured for use. Loading the OmrTemplateDocument and the AtalaImages into the engine is the last step to get the results back from the engine.
C#
private void ProcessDocument(string TemplateFileName, string ImageFileName)
{
OmrTemplateDocument ActiveTemplate = OmrTemplateDocument.Load(TemplateFileName);
OmrEngine engine = new OmrEngine();
OmrDocument result = engine.RecognizeDocument(new FileSystemImageSource(ImageFileName, true), ActiveTemplate);
OmrPage page = result.Pages[0];
ParsePage(page);
}
VB.NET
Private Sub ProcessDocument(TemplateFileName As String, ImageFileName As String)
Dim ActiveTemplate As OmrTemplateDocument = OmrTemplateDocument.Load(TemplateFileName)
Dim engine As New OmrEngine()
Dim result As OmrDocument = engine.RecognizeDocument(New FileSystemImageSource(ImageFileName, True), ActiveTemplate)
Dim page As OmrPage = result.Pages(0)
ParsePage(page)
End Sub
To get relevant information out of the OmrPage object simply parse out the valuable information of its collections. The following sample records all the marked fields to a display:
C#
private void ParsePage(OmrPage page)
{
foreach (OmrGroup g in page.Groups)
{
foreach (OmrMark m in g.Marks)
if (m.IsMarked)
AddResultToDisplay(g.Template.Name + " " + m.Template.Name);
else
AddResultToDisplay("NOTMARKED: " + g.Template.Name + " " + m.Template.Name + " @ " + m.Template.Rectangle.ToString());
}
}
VB.NET
Private Sub ParsePage(page As OmrPage)
For Each g As OmrGroup In page.Groups
For Each m As OmrMark In g.Marks
If m.IsMarked Then
AddResultToDisplay(g.Template.Name + " " + m.Template.Name)
Else
AddResultToDisplay(("NOTMARKED: " + g.Template.Name & " ") + m.Template.Name & " @ " & m.Template.Rectangle.ToString())
End If
Next
Next
End Sub
Additional Articles / Resources
INFO: Getting Started with Optical Mark Recognition (OMR) / Forms Processing
Original Article:
Q10320 - INFO: Mark Detection Basics