[SerializableAttribute()]public enum OcrOmrSensitivity
| Value | Member | Description |
|---|---|---|
| 0 | Highest | Use the highest check mark recognition sensitivity. This may also be the slowest. |
| 1 | High | Use high check mark recognition sensitivity. |
| 2 | Low | Use low check mark recognition sensitivity. May be faster than High. |
| 3 | Lowest | Use the lowest check mark recognition sensitivity. This may also be the fastest. |
OMR stands for Optical Mark Recognition. For more information refer to Using OMR in LEADTOOLS .NET OCR.
You can set the LEADTOOLS OCR engine OMR recognition sensitivity to be as high or low as desired. High sensitivity results in higher confidence in the recognized mark, but could prove to be slower.
To change the sensitivity of OMR recognition, use Sensitivity.
using Leadtools;using Leadtools.Codecs;using Leadtools.Ocr;using Leadtools.Forms.Common;using Leadtools.Document.Writer;using Leadtools.WinForms;public void OcrOmrExample(){// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);// We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marksstring tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif");// Create an OCR documentusing (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()){// Add a page to the documentIOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null);// Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviouslyLeadRect[] omrBounds ={new LeadRect(484, 98, 84, 78),new LeadRect(494, 184, 70, 54),new LeadRect(498, 244, 76, 76)};foreach (LeadRect omrBound in omrBounds){// Create a new OMR zone and add it to the pageOcrZone zone = new OcrZone();zone.ZoneType = OcrZoneType.Omr;zone.Bounds = omrBound;ocrPage.Zones.Add(zone);}// Show how many zones we have and they propertiesConsole.WriteLine("Page has {0} zones:", ocrPage.Zones.Count);for (int i = 0; i < ocrPage.Zones.Count; i++){OcrZone zone = ocrPage.Zones[i];Console.WriteLine("{0}: Type: {1}", i + 1, zone.ZoneType);}// Change the OMR options (Auto detection of frames with highest sensitivity)IOcrOmrOptions omrOptions = ocrEngine.ZoneManager.OmrOptions;omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto;omrOptions.Sensitivity = OcrOmrSensitivity.Highest;// Get the character we are using in the engine to represent the filled/unfilled stateschar filledCode = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Filled);char unfilledCode = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Unfilled);// Recognize the pageConsole.WriteLine("Recognizing...");ocrPage.Recognize(null);IOcrPageCharacters pageCharacters = ocrPage.GetRecognizedCharacters();foreach (IOcrZoneCharacters zoneCharacters in pageCharacters){// We must have one character (the state for each OMR zone)Debug.Assert(zoneCharacters.Count == 1);OcrCharacter character = zoneCharacters[0];Debug.Assert(character.Code == filledCode || character.Code == unfilledCode);Console.WriteLine("{0}: State: {1}, Confidence: {2}", zoneCharacters.ZoneIndex, character.Code == filledCode ? "Filled" : "Unfilled", character.Confidence);}// Now save the result as PDF using the default characters representation for OMR states (0 for unfilled, 1 for filled)string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Omr_Results1.pdf");Console.WriteLine("Saving to {0}...", pdfFileName1);ocrDocument.Save(pdfFileName1, DocumentFormat.Pdf, null);// Change the character representation for the OMR states to Y for unfilled, and X for filledomrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Unfilled, 'Y');omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Filled, 'X');string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Omr_Results2.pdf");Console.WriteLine("Saving to {0}...", pdfFileName2);ocrDocument.Save(pdfFileName2, DocumentFormat.Pdf, null);}// Shutdown the engine// Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown();}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime";}