←Select platform

FrameDetectionMethod Property

Summary
Gets or sets the OMR frame detection mode.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public OcrOmrFrameDetectionMethod FrameDetectionMethod { get; set; } 
@property (nonatomic, assign) LTOcrOmrFrameDetectionMethod frameDetectionMethod 
public OcrOmrFrameDetectionMethod getFrameDetectionMethod() 
public void setFrameDetectionMethod(OcrOmrFrameDetectionMethod value) 
property OcrOmrFrameDetectionMethod FrameDetectionMethod { 
   OcrOmrFrameDetectionMethod get(); 
   void set (    OcrOmrFrameDetectionMethod ); 
} 
FrameDetectionMethod # get and set (IOcrOmrOptions) 

Property Value

An OcrOmrFrameDetectionMethod enumeration member that indicates the OMR frame detection mode.

Remarks

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

Frames stand for the checkbox that may exist around OMR fields. You can set the LEADTOOLS OCR engine to automatically detect these frames and take them into consideration when recognizing OMR fields. If you know the OMR fields contains (or does not contain) frames, it is recommended to set IOcrOmrOptions.FrameDetectionMethod accordingly to increase the recognition performance and accuracy.

Example
C#
Java
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 engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.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 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 
         LeadRect[] 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 page 
            OcrZone zone = new OcrZone(); 
            zone.ZoneType = OcrZoneType.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}", 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 states 
         char filledCode = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Filled); 
         char unfilledCode = omrOptions.GetStateRecognitionCharacter(OcrOmrZoneState.Unfilled); 
 
         // Recognize the page 
         Console.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 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:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
 
import static org.junit.Assert.assertTrue; 
 
import java.io.File; 
import java.io.IOException; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.ocr.*; 
import leadtools.document.writer.*; 
 
 
public void IOcrOmrOptionsExample() { 
   final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   // Create an instance of the engine 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
 
   // Start the engine using default parameters 
   ocrEngine.startup(null, null, null, OCR_LEAD_RUNTIME_DIR); 
   assertTrue(ocrEngine.isStarted()); 
 
   // We will use Mixed.tif shipped with LEADTOOLS in the Images folder. This image 
   // has 3 OMR check marks 
   String tifFileName = combine(LEAD_VARS_IMAGES_DIR, "Mixed.tif"); 
 
   // Create an OCR document 
   OcrDocument ocrDocument = ocrEngine.getDocumentManager().createDocument(); 
 
   // Add a page to the document 
   RasterCodecs c = new RasterCodecs(); 
   OcrPage ocrPage = ocrDocument.getPages().addPage(c.load(tifFileName), null); // ocrprogress listener thing again, 
                                                                                // look in teams chat 
 
   // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image 
   // previously 
   LeadRect[] omrBounds = { 
         new LeadRect(484, 98, 84, 78), 
         new LeadRect(494, 184, 70, 54), 
         new LeadRect(498, 244, 76, 76) 
   }; 
 
   for (LeadRect omrBound : omrBounds) { 
      // Create a new OMR zone and add it to the page 
      OcrZone zone = new OcrZone(); 
      zone.setZoneType(OcrZoneType.OMR); 
      zone.setBounds(omrBound); 
      ocrPage.getZones().add(zone); 
   } 
 
   // Show how many zones we have and they properties 
   System.out.printf("Page has %s zones:", ocrPage.getZones().size()); // count syntax? 
   for (int i = 0; i < ocrPage.getZones().size(); i++) { 
      OcrZone zone = ocrPage.getZones().get(i); // syntax for zones with brackets 
      System.out.printf("%s: Type: %s", i + 1, zone.getZoneType()); 
 
      assertTrue("Incorrect size", ocrPage.getZones().size() == 3); 
   } 
 
   // Change the OMR options (Auto detection of frames with highest sensitivity) 
   OcrOmrOptions omrOptions = ocrEngine.getZoneManager().getOmrOptions(); 
   omrOptions.setFrameDetectionMethod(OcrOmrFrameDetectionMethod.AUTO); 
   omrOptions.setSensitivity(OcrOmrSensitivity.HIGHEST); 
 
   // Get the character we are using in the engine to represent the filled/unfilled 
   // states 
   char filledCode = omrOptions.getStateRecognitionCharacter(OcrOmrZoneState.FILLED); 
   char unfilledCode = omrOptions.getStateRecognitionCharacter(OcrOmrZoneState.UNFILLED); 
 
   // Recognize the page 
   System.out.println("Recognizing..."); 
   ocrPage.recognize(null); 
 
   OcrPageCharacters pageCharacters = ocrPage.getRecognizedCharacters(); 
   for (int i = 0; i < pageCharacters.size(); i++) { 
      // We must have one character (the state for each OMR zone) 
      OcrCharacter character = pageCharacters.get(i).get(0); 
      assert(character.getCode() == filledCode || character.getCode() == unfilledCode); 
      System.out.printf("%s: State: %s, Confidence:%s ", pageCharacters.get(i).getZoneIndex(), 
            character.getCode() == filledCode ? "Filled" : "Unfilled", character.getConfidence()); 
   } 
 
   // Now save the result as PDF using the default characters representation for 
   // OMR states (0 for unfilled, 1 for filled) 
   String pdfFileName1 = combine(LEAD_VARS_IMAGES_DIR, "Omr_Results1.pdf"); 
   System.out.printf("Saving to %s...", 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 = combine(LEAD_VARS_IMAGES_DIR, "Omr_Results2.pdf"); 
   System.out.printf("Saving to %s...", pdfFileName2); 
   ocrDocument.save(pdfFileName2, DocumentFormat.PDF, null); 
   ocrDocument.dispose(); 
 
   // Shutdown the engine 
   // Note: calling Dispose will also automatically shutdown the engine if it has 
   // been started 
   ocrEngine.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.