OmrField Class
Summary
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.
Syntax
[SerializableAttribute()]
[DataContractAttribute()]
public class OmrField : Field
<SerializableAttribute(),
DataContractAttribute()>
Public Class OmrField
Inherits Field
public:
[SerializableAttribute,
DataContractAttribute]
ref class OmrField : Field
Example
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 example in Visual Studio 2017.
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);
}