The OMR (Optical Mark Recognition) settings currently used by the engine.
public interface IOcrOmrOptions Public Interface IOcrOmrOptions @interface LTOcrOmrOptions : NSObject public class OcrOmrOptions public interface class IOcrOmrOptions
Use of OMR in LEADTOOLS requires a special key to unlock OMR capabilities. For more information, refer to Unlocking Special LEAD Features.
To get the instance of the IOcrOmrOptions interface currently used in the engine call the IOcrSpellCheckManager.OmrOptions property.
Use the IOcrOmrOptions interface to change the following OMR settings:
The OMR zones of a page are zones that have the OcrZone.ZoneType set to OcrZoneType.Omr.
All LEADTOOLS OCR engines support OMR. However, only the LEADTOOLS OCR Module - LEAD Engine supports auto-detection of OMR zones during auto-zoning of the OCR page. To set up OMR zone auto-detection, make sure that the "Detect Checkbox" is one of the Recognition.Zoning.Options setting flags included before calling IOcrPage.AutoZone or IOcrPage.Recognize. The rest of the OCR engines require that the OMR zones be manually added to the page by setting their boundaries through OcrZone.Bounds and zone type as described above. Then add the zones to the page using the IOcrPage.Zones collection before calling IOcrPage.Recognize.
For more information refer to Using OMR in LEADTOOLS .NET OCR.
This example will load a TIF image, create OMR zones and recognize them.
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, false)){// 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:\Users\Public\Documents\LEADTOOLS Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.OcrImports Leadtools.FormsImports Leadtools.Document.WriterImports Leadtools.WinFormsPublic Sub OcrOmrExample()' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)' We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marksDim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif")' Create an OCR documentUsing ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()' Add a page to the documentDim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)' Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviouslyDim omrBounds As LeadRect() = {New LeadRect(484, 98, 84, 78),New LeadRect(494, 184, 70, 54),New LeadRect(498, 244, 76, 76)}For Each omrBound As LeadRect In omrBounds' Create a new OMR zone and add it to the pageDim zone As New OcrZone()zone.ZoneType = OcrZoneType.Omrzone.Bounds = omrBoundocrPage.Zones.Add(zone)Next' Show how many zones we have and they propertiesConsole.WriteLine("Page has {0} zones:", ocrPage.Zones.Count)For i As Integer = 0 To ocrPage.Zones.Count - 1Dim zone As OcrZone = ocrPage.Zones(i)Console.WriteLine("{0}: Type: {1}", i + 1, zone.ZoneType)Next' Change the OMR options (Auto detection of frames with highest sensitivity)Dim omrOptions As IOcrOmrOptions = ocrEngine.ZoneManager.OmrOptionsomrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.AutoomrOptions.Sensitivity = OcrOmrSensitivity.Highest' Get the character we are using in the engine to represent the filled/unfilled statesDim filledCode As Char = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Filled)Dim unfilledCode As Char = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Unfilled)' Recognize the pageConsole.WriteLine("Recognizing...")ocrPage.Recognize(Nothing)Dim pageCharacters As IOcrPageCharacters = ocrPage.GetRecognizedCharacters()For Each zoneCharacters As IOcrZoneCharacters In pageCharacters' We must have one character (the state for each OMR zone)Debug.Assert(zoneCharacters.Count = 1)Dim character As OcrCharacter = zoneCharacters(0)Debug.Assert(character.Code = filledCode OrElse character.Code = unfilledCode)Console.WriteLine("{0}: State: {1}, Confidence: {2}",zoneCharacters.ZoneIndex,If(character.Code = filledCode, "Filled", "Unfilled"),character.Confidence)Next' Now save the result as PDF using the default characters representation for OMR states (0 for unfilled, 1 for filled)Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Omr_Results1.pdf")Console.WriteLine("Saving to {0}...", pdfFileName1)ocrDocument.Save(pdfFileName1, DocumentFormat.Pdf, Nothing)' Change the character representation for the OMR states to Y for unfilled, and X for filledomrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Unfilled, "Y"c)omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Filled, "X"c)Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Omr_Results2.pdf")Console.WriteLine("Saving to {0}...", pdfFileName2)ocrDocument.Save(pdfFileName2, DocumentFormat.Pdf, Nothing)End Using' Shutdown the engine' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
