←Select platform

SetStateRecognitionCharacter Method

Summary
Sets the character used to represent an OMR state in the output document.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SetStateRecognitionCharacter( 
   OcrOmrZoneState state, 
   char value 
) 
- (void)setRecognitionCharacter:(unichar)character forState:(LTOcrOmrZoneState)state; 
public void setStateRecognitionCharacter(OcrOmrZoneState state, 
                                         char value) 
void SetStateRecognitionCharacter(  
   OcrOmrZoneState state, 
   char value 
)  
def SetStateRecognitionCharacter(self,state,value): 

Parameters

state
The OMR state for this character.

value
The character value.

Remarks

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

When performing OMR recognition, you can obtain the OMR results by inspecting the OcrCharacter.Code property. Moreover the engine will add a character to represent each zone (mark) state into the recognition results. This character will then be outputted to the final document when IOcrDocument.Save or IOcrDocument.SaveXml is called.

The character will also be present as the zone data when calling IOcrPage.GetRecognizedCharacters.

The default characters used in the IOcrEngine is as follows:

State Value
OcrOmrZoneState.Unfilled 0
OcrOmrZoneState.Filled 1

You can get the current values using the GetStateRecognitionCharacter method, you can also change them using the SetStateRecognitionCharacter method. If you do not want any OMR characters to show up in the final document, you can set all state characters to ' ' (a space character).

Example
C#
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:\LEADTOOLS22\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

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

Leadtools.Ocr Assembly

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