A class that represents a single rectangular region on a form that defines an OMR (optical mark) area on a blank (not filled-in) form. Thus, an OMR reading process can be performed on the filled form during OMR processing.
[SerializableAttribute()]
[DataContractAttribute()]
public class OmrField : Field
Fields are defined for each Omr page in the ITemplateForm. Each field requires a name and its bounds to specify where it is located on the page.
Fields can be added or retrieved using the Page.Fields property. Once defined, the fields can be saved or loaded using IForm.Save and IForm.Load methods.
LEADTOOLS supports OmrFields, OcrField, ImageField and BarcodeField.
Each field contains the FieldResult property that must be cast to the appropriate type in order to obtain the field-specific results (Omr, Image, etc).
OmrFields supports different shapes of OMR areas in the OMR form, such as single OMR column, single OMR row or a matrix of OMR marks.
OmrFields properties can be auto extracted and populated from the OMR form using the method ITemplateForm-ExtractInfo.
Note
The following example is a snippet of a larger example project. To run the larger example project, follow the work flow laid out in the OMREngine example. You can also download the complete Visual Studio 2017 project.
using Leadtools;
using Leadtools.Barcode;
using Leadtools.Codecs;
using Leadtools.Forms.Processing.Omr;
using Leadtools.Forms.Processing.Omr.Fields;
using Leadtools.Ocr;
public static void AddZonesToTemplate(ITemplateForm template)
{
// create two different zones with definitive boundaries
OmrField firstNameField = new OmrField();
firstNameField.Bounds = new LeadRect(152, 768, 788, 1276);
firstNameField.Name = "FirstName";
firstNameField.PageNumber = 1;
OmrField testField = new OmrField();
testField.Bounds = new LeadRect(148, 2067, 384, 900);
testField.PageNumber = 1;
testField.Name = "Questions 1-15";
// parse the template document for any Omr regions in the boundaries
template.ExtractInfo(1, new Field[] { firstNameField, testField });
// get the options for the first field (this field is an Alphabetic "Name" field)
OmrFieldOptions firstNameOptions = firstNameField.Options;
firstNameOptions.FieldOrientation = OmrFieldOrientation.ColumnWise; // this region should be decomposed into columns
firstNameOptions.TextFormat = OmrTextFormat.Aggregated; // these values are contiguous and merged together (such as individual letters in a name)
firstNameOptions.GradeThisField = false; // this region will not be included in statistics generation
firstNameField.Options = firstNameOptions;
OmrFieldOptions testFieldOptions = testField.Options;
testFieldOptions.FieldOrientation = OmrFieldOrientation.RowWise; // this region should be decomposed into rows
testFieldOptions.TextFormat = OmrTextFormat.CSV; // these values are independent and kept separate (such as multiple choice answers)
testFieldOptions.GradeThisField = true; // this region will have statistics generated for it
testFieldOptions.CorrectGrade = 1.0; // the relative weight of this region if this matches the answer key (reward for correct answer)
testFieldOptions.IncorrectGrade = 0.0; // relative weight of this region if it does not match the answer key (active penalty for incorrect answers)
testFieldOptions.NoResponseGrade = 0.0; // relative weight of this region if no response present (active penalty for failing to answer)
testField.Options = testFieldOptions;
// GenerateOmrFieldValues.Generate() is a helper function to make value sets based on the dimension
// for this dimension and orientation, the output range is:
// [0] 0 -> 25
// [1] 1 -> 26
// [2] 25 -> 0
// [3] 26 -> 1
// [4] A -> Z
// [5] Z -> A
List<List<string>> availableFirstNameRanges = GenerateOmrFieldValues.Generate(firstNameField.RowsCount, firstNameField.ColumnsCount, firstNameField.Options.FieldOrientation);
firstNameField.SetValues(availableFirstNameRanges[4]); // this index contains the basic English alphabet
// a custom list can also be used as long as it contains the same number of elements based on dimension and orientation
// a row-wise orientation with four columns in each row requires four values
testField.SetValues(new List<string>() { "A", "B", "C", "D" });
template.Pages[0].Fields.Add(firstNameField);
template.Pages[0].Fields.Add(testField);
}