LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)
LEAD Technologies, Inc

IOcrOmrOptions Interface

Example 





Members 
The OMR settings currently used in the engine. .NET support
Object Model
IOcrOmrOptions Interface
Syntax
public interface IOcrOmrOptions 
'Declaration
 
Public Interface IOcrOmrOptions 
'Usage
 
Dim instance As IOcrOmrOptions
public interface IOcrOmrOptions 
function Leadtools.Forms.Ocr.IOcrOmrOptions() 
public interface class IOcrOmrOptions 
Remarks

OMR stands for Optical Mark Recognition. For more information refer to Using OMR in LEADTOOLS .NET OCR.

You can get the instance of the IOcrOmrOptions interface currently used in the engine with the IOcrSpellCheckManager.OmrOptions property.

With the IOcrOmrOptions interface, you can change the following OMR settings:

After you call IOcrPage.Recognize, all the OMR zones in the page will have the OMR properties updated as follows:

Property Description
OcrZone.OmrState Either OcrOmrZoneState.Filled if the mark is recognized to be filled or checked, or OcrOmrZoneState.Unfilled if the mark is recognized to be unfilled or unchecked.
OcrZone.OmrConfidence A number between 0 and 100 (where 100 is maximum confidence) that specifies the OCR engine confidence in the recognition status in OcrZone.OmrState.

The OMR zones of a page are zones with the following properties:

Property Value
OcrZone.FillMethod Set to OcrZoneFillMethod.Omr
OcrZone.RecognitionModule Set to OcrZoneRecognitionModule.Omr

All LEADTOOLS OCR engines support OMR. However, there is no current support for auto-detecting OMR zones in a page, you have to add the OMR zones manually to the page by setting their boundary (through OcrZone.Bounds, the fill method and recognition module as described above and adding the zone to the page using the IOcrPage.Zones collection before calling IOcrPage.Recognize.

To use OMR in LEADTOOLS, you need a special key to unlock the OMR capabilities. For more information, refer to Unlocking Special LEAD Features.

Example
Copy CodeCopy Code  
Private Sub OcrOmrExample()
      ' Create an instance of the engine
      Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
         ' Start the engine using default parameters
         ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
         ' We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
         Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif")

         ' Create an OCR document
         Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
            ' Add a page to the document
            Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)

            ' Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
            Dim omrBounds() As LogicalRectangle = _
            { _
               New LogicalRectangle(484, 98, 84, 78, LogicalUnit.Pixel), _
               New LogicalRectangle(494, 184, 70, 54, LogicalUnit.Pixel), _
               New LogicalRectangle(498, 244, 76, 76, LogicalUnit.Pixel) _
            }

            For Each omrBound As LogicalRectangle In omrBounds
               ' Create a new OMR zone and add it to the page
               Dim zone As New OcrZone()
               zone.ZoneType = OcrZoneType.Text
               zone.FillMethod = OcrZoneFillMethod.Omr
               zone.RecognitionModule = OcrZoneRecognitionModule.Omr
               zone.Bounds = omrBound
               ocrPage.Zones.Add(zone)
            Next

            ' Show how many zones we have and they properties
            Console.WriteLine("Page has {0} zones:", ocrPage.Zones.Count)
            For i As Integer = 0 To ocrPage.Zones.Count - 1
               Dim zone As OcrZone = ocrPage.Zones(i)
               Console.WriteLine("{0}: Type: {1}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule)
            Next

            ' Change the OMR options (Auto detection of frames with highest sensitivity)
            Dim omrOptions As IOcrOmrOptions = ocrEngine.ZoneManager.OmrOptions
            omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto
            omrOptions.Sensitivity = OcrOmrSensitivity.Highest

            ' Recognize the page
            Console.WriteLine("Recognizing...")
            ocrPage.Recognize(Nothing)

            ' Now show the OMR zone properties
            For i As Integer = 0 To ocrPage.Zones.Count - 1
               Dim zone As OcrZone = ocrPage.Zones(i)
               Console.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence)
            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 filled
            omrOptions.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 started
         ocrEngine.Shutdown()
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
private void OcrOmrExample()
   {
      // Create an instance of the engine
      using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false))
      {
         // Start the engine using default parameters
         ocrEngine.Startup(null, null, null, null);
         // We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
         string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif");

         // Create an OCR document
         using(IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
         {
            // Add a page to the document
            IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null);

            // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
            LogicalRectangle[] omrBounds =
            {
               new LogicalRectangle(484, 98, 84, 78, LogicalUnit.Pixel),
               new LogicalRectangle(494, 184, 70, 54, LogicalUnit.Pixel),
               new LogicalRectangle(498, 244, 76, 76, LogicalUnit.Pixel)
            };

            foreach(LogicalRectangle omrBound in omrBounds)
            {
               // Create a new OMR zone and add it to the page
               OcrZone zone = new OcrZone();
               zone.ZoneType = OcrZoneType.Text;
               zone.FillMethod = OcrZoneFillMethod.Omr;
               zone.RecognitionModule = OcrZoneRecognitionModule.Omr;
               zone.Bounds = omrBound;
               ocrPage.Zones.Add(zone);
            }

            // Show how many zones we have and they properties
            Console.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}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule);
            }

            // Change the OMR options (Auto detection of frames with highest sensitivity)
            IOcrOmrOptions omrOptions = ocrEngine.ZoneManager.OmrOptions;
            omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto;
            omrOptions.Sensitivity = OcrOmrSensitivity.Highest;

            // Recognize the page
            Console.WriteLine("Recognizing...");
            ocrPage.Recognize(null);

            // Now show the OMR zone properties
            for(int i = 0; i < ocrPage.Zones.Count; i++)
            {
               OcrZone zone = ocrPage.Zones[i];
               Console.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence);
            }

            // 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 filled
            omrOptions.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 started
         ocrEngine.Shutdown();
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
private async void OcrOmrExample()
{
   // Create an instance of the engine
   IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
   // Start the engine using default parameters
   ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath);

   // We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
   string tifFileName = "Mixed.tif";

   // Create an OCR document
   IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

   // Add a page to the document
   IOcrPage ocrPage = null;
   using (RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName);
      using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
         ocrPage = ocrDocument.Pages.AddPage(image, null);
   }

   // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
   LeadRect[] omrBounds =
   {
      LeadRectHelper.Create(484, 98, 84, 78),
      LeadRectHelper.Create(494, 184, 70, 54),
      LeadRectHelper.Create(498, 244, 76, 76)
   };

   foreach(LeadRect omrBound in omrBounds)
   {
      // Create a new OMR zone and add it to the page
      OcrZone zone = new OcrZone();
      zone.ZoneType = OcrZoneType.Text;
      zone.FillMethod = OcrZoneFillMethod.Omr;
      zone.RecognitionModule = OcrZoneRecognitionModule.Omr;
      zone.Bounds = omrBound;
      ocrPage.Zones.Add(zone);
   }

   // Show how many zones we have and they properties
   Debug.WriteLine("Page has {0} zones:", ocrPage.Zones.Count);
   for(int i = 0; i < ocrPage.Zones.Count; i++)
   {
      OcrZone zone = ocrPage.Zones[i];
      Debug.WriteLine("{0}: Type: {1}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule);
   }

   // Change the OMR options (Auto detection of frames with highest sensitivity)
   IOcrOmrOptions omrOptions = ocrEngine.ZoneManager.OmrOptions;
   omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto;
   omrOptions.Sensitivity = OcrOmrSensitivity.Highest;

   // Recognize the page
   Debug.WriteLine("Recognizing...");
   ocrPage.Recognize(null);

   // Now show the OMR zone properties
   for(int i = 0; i < ocrPage.Zones.Count; i++)
   {
      OcrZone zone = ocrPage.Zones[i];
      Debug.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence);
   }

   // Now save the result as PDF using the default characters representation for OMR states (0 for unfilled, 1 for filled)
   string pdfFileName1 = "Omr_Results1.pdf";
   Debug.WriteLine("Saving to {0}...", pdfFileName1);
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName1, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Change the character representation for the OMR states to Y for unfilled, and X for filled
   omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Unfilled, 'Y');
   omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Filled, 'X');

   string pdfFileName2 = "Omr_Results2.pdf";
   Debug.WriteLine("Saving to {0}...", pdfFileName2);
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName2, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Shutdown the engine
   ocrEngine.Shutdown();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IOcrOmrOptions Members
Leadtools.Forms.Ocr Namespace
OcrEngineManager Class
OcrEngineType Enumeration
IOcrPageCollection Interface
IOcrZoneCollection Interface
IOcrZoneManager Interface
OcrZone Structure
OcrZoneRecognitionModule Enumeration
OcrZoneFillMethod Enumeration
Programming with the LEADTOOLS .NET OCR
Using OMR in LEADTOOLS .NET OCR
Unlocking Special LEAD Features

The OMR settings currently used in the engine. .NET support
Object Model
IOcrOmrOptions Interface
Syntax
public interface IOcrOmrOptions 
'Declaration
 
Public Interface IOcrOmrOptions 
'Usage
 
Dim instance As IOcrOmrOptions
public interface IOcrOmrOptions 
function Leadtools.Forms.Ocr.IOcrOmrOptions() 
public interface class IOcrOmrOptions 
Remarks

OMR stands for Optical Mark Recognition. For more information refer to Using OMR in LEADTOOLS .NET OCR.

You can get the instance of the IOcrOmrOptions interface currently used in the engine with the IOcrSpellCheckManager.OmrOptions property.

With the IOcrOmrOptions interface, you can change the following OMR settings:

After you call IOcrPage.Recognize, all the OMR zones in the page will have the OMR properties updated as follows:

Property Description
OcrZone.OmrState Either OcrOmrZoneState.Filled if the mark is recognized to be filled or checked, or OcrOmrZoneState.Unfilled if the mark is recognized to be unfilled or unchecked.
OcrZone.OmrConfidence A number between 0 and 100 (where 100 is maximum confidence) that specifies the OCR engine confidence in the recognition status in OcrZone.OmrState.

The OMR zones of a page are zones with the following properties:

Property Value
OcrZone.FillMethod Set to OcrZoneFillMethod.Omr
OcrZone.RecognitionModule Set to OcrZoneRecognitionModule.Omr

All LEADTOOLS OCR engines support OMR. However, there is no current support for auto-detecting OMR zones in a page, you have to add the OMR zones manually to the page by setting their boundary (through OcrZone.Bounds, the fill method and recognition module as described above and adding the zone to the page using the IOcrPage.Zones collection before calling IOcrPage.Recognize.

To use OMR in LEADTOOLS, you need a special key to unlock the OMR capabilities. For more information, refer to Unlocking Special LEAD Features.

Example
Copy CodeCopy Code  
Private Sub OcrOmrExample()
      ' Create an instance of the engine
      Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
         ' Start the engine using default parameters
         ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
         ' We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
         Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif")

         ' Create an OCR document
         Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
            ' Add a page to the document
            Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)

            ' Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
            Dim omrBounds() As LogicalRectangle = _
            { _
               New LogicalRectangle(484, 98, 84, 78, LogicalUnit.Pixel), _
               New LogicalRectangle(494, 184, 70, 54, LogicalUnit.Pixel), _
               New LogicalRectangle(498, 244, 76, 76, LogicalUnit.Pixel) _
            }

            For Each omrBound As LogicalRectangle In omrBounds
               ' Create a new OMR zone and add it to the page
               Dim zone As New OcrZone()
               zone.ZoneType = OcrZoneType.Text
               zone.FillMethod = OcrZoneFillMethod.Omr
               zone.RecognitionModule = OcrZoneRecognitionModule.Omr
               zone.Bounds = omrBound
               ocrPage.Zones.Add(zone)
            Next

            ' Show how many zones we have and they properties
            Console.WriteLine("Page has {0} zones:", ocrPage.Zones.Count)
            For i As Integer = 0 To ocrPage.Zones.Count - 1
               Dim zone As OcrZone = ocrPage.Zones(i)
               Console.WriteLine("{0}: Type: {1}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule)
            Next

            ' Change the OMR options (Auto detection of frames with highest sensitivity)
            Dim omrOptions As IOcrOmrOptions = ocrEngine.ZoneManager.OmrOptions
            omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto
            omrOptions.Sensitivity = OcrOmrSensitivity.Highest

            ' Recognize the page
            Console.WriteLine("Recognizing...")
            ocrPage.Recognize(Nothing)

            ' Now show the OMR zone properties
            For i As Integer = 0 To ocrPage.Zones.Count - 1
               Dim zone As OcrZone = ocrPage.Zones(i)
               Console.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence)
            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 filled
            omrOptions.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 started
         ocrEngine.Shutdown()
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
private void OcrOmrExample()
   {
      // Create an instance of the engine
      using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false))
      {
         // Start the engine using default parameters
         ocrEngine.Startup(null, null, null, null);
         // We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
         string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Mixed.tif");

         // Create an OCR document
         using(IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
         {
            // Add a page to the document
            IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null);

            // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
            LogicalRectangle[] omrBounds =
            {
               new LogicalRectangle(484, 98, 84, 78, LogicalUnit.Pixel),
               new LogicalRectangle(494, 184, 70, 54, LogicalUnit.Pixel),
               new LogicalRectangle(498, 244, 76, 76, LogicalUnit.Pixel)
            };

            foreach(LogicalRectangle omrBound in omrBounds)
            {
               // Create a new OMR zone and add it to the page
               OcrZone zone = new OcrZone();
               zone.ZoneType = OcrZoneType.Text;
               zone.FillMethod = OcrZoneFillMethod.Omr;
               zone.RecognitionModule = OcrZoneRecognitionModule.Omr;
               zone.Bounds = omrBound;
               ocrPage.Zones.Add(zone);
            }

            // Show how many zones we have and they properties
            Console.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}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule);
            }

            // Change the OMR options (Auto detection of frames with highest sensitivity)
            IOcrOmrOptions omrOptions = ocrEngine.ZoneManager.OmrOptions;
            omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto;
            omrOptions.Sensitivity = OcrOmrSensitivity.Highest;

            // Recognize the page
            Console.WriteLine("Recognizing...");
            ocrPage.Recognize(null);

            // Now show the OMR zone properties
            for(int i = 0; i < ocrPage.Zones.Count; i++)
            {
               OcrZone zone = ocrPage.Zones[i];
               Console.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence);
            }

            // 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 filled
            omrOptions.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 started
         ocrEngine.Shutdown();
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
private async void OcrOmrExample()
{
   // Create an instance of the engine
   IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
   // Start the engine using default parameters
   ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath);

   // We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image has 3 OMR check marks
   string tifFileName = "Mixed.tif";

   // Create an OCR document
   IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

   // Add a page to the document
   IOcrPage ocrPage = null;
   using (RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName);
      using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
         ocrPage = ocrDocument.Pages.AddPage(image, null);
   }

   // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image perviously
   LeadRect[] omrBounds =
   {
      LeadRectHelper.Create(484, 98, 84, 78),
      LeadRectHelper.Create(494, 184, 70, 54),
      LeadRectHelper.Create(498, 244, 76, 76)
   };

   foreach(LeadRect omrBound in omrBounds)
   {
      // Create a new OMR zone and add it to the page
      OcrZone zone = new OcrZone();
      zone.ZoneType = OcrZoneType.Text;
      zone.FillMethod = OcrZoneFillMethod.Omr;
      zone.RecognitionModule = OcrZoneRecognitionModule.Omr;
      zone.Bounds = omrBound;
      ocrPage.Zones.Add(zone);
   }

   // Show how many zones we have and they properties
   Debug.WriteLine("Page has {0} zones:", ocrPage.Zones.Count);
   for(int i = 0; i < ocrPage.Zones.Count; i++)
   {
      OcrZone zone = ocrPage.Zones[i];
      Debug.WriteLine("{0}: Type: {1}, Fill method: {2}, Recognition Module: {3}", i + 1, zone.ZoneType, zone.FillMethod, zone.RecognitionModule);
   }

   // Change the OMR options (Auto detection of frames with highest sensitivity)
   IOcrOmrOptions omrOptions = ocrEngine.ZoneManager.OmrOptions;
   omrOptions.FrameDetectionMethod = OcrOmrFrameDetectionMethod.Auto;
   omrOptions.Sensitivity = OcrOmrSensitivity.Highest;

   // Recognize the page
   Debug.WriteLine("Recognizing...");
   ocrPage.Recognize(null);

   // Now show the OMR zone properties
   for(int i = 0; i < ocrPage.Zones.Count; i++)
   {
      OcrZone zone = ocrPage.Zones[i];
      Debug.WriteLine("{0}: State: {1}, Confidence: {2}", i + 1, zone.OmrState, zone.OmrConfidence);
   }

   // Now save the result as PDF using the default characters representation for OMR states (0 for unfilled, 1 for filled)
   string pdfFileName1 = "Omr_Results1.pdf";
   Debug.WriteLine("Saving to {0}...", pdfFileName1);
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName1, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Change the character representation for the OMR states to Y for unfilled, and X for filled
   omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Unfilled, 'Y');
   omrOptions.SetStateRecognitionCharacter(OcrOmrZoneState.Filled, 'X');

   string pdfFileName2 = "Omr_Results2.pdf";
   Debug.WriteLine("Saving to {0}...", pdfFileName2);
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName2, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Shutdown the engine
   ocrEngine.Shutdown();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IOcrOmrOptions Members
Leadtools.Forms.Ocr Namespace
OcrEngineManager Class
OcrEngineType Enumeration
IOcrPageCollection Interface
IOcrZoneCollection Interface
IOcrZoneManager Interface
OcrZone Structure
OcrZoneRecognitionModule Enumeration
OcrZoneFillMethod Enumeration
Programming with the LEADTOOLS .NET OCR
Using OMR in LEADTOOLS .NET OCR
Unlocking Special LEAD Features

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

IOcrOmrOptions requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features