←Select platform

OcrZoneCharacterFilters Enumeration

Character set filter.
public enum OcrZoneCharacterFilters 
typedef NS_OPTIONS(NSUInteger, LTOcrZoneCharacterFilters) 
public enum OcrZoneCharacterFilters 
public enum class OcrZoneCharacterFilters   
class OcrZoneCharacterFilters(Enum): 
   None = 0 
   Digit = 1 
   Uppercase = 2 
   Lowercase = 4 
   Alpha = 6 
   Punctuation = 8 
   Miscellaneous = 16 
   All = 31 
   Plus = 32 
   Numbers = 33 
0x00000000None No character filters.
0x00000001Digit Recognition of numerals. For example: "3" (Digit Three).
0x00000002Uppercase Recognition of uppercase letters, including accented ones. For example: "A" (Capital A).
0x00000004Lowercase Recognition of lowercase letters including accented ones. For example: "a" (Lowercase a).
0x00000006Alpha Upper and lowercase letters. This is a combination of (Uppercase | Lowercase).
0x00000008Punctuation Recognition of punctuation signs. For example: "!" (Exclamation Mark).
0x00000010Miscellaneous Recognition of other miscellaneous characters. For example: "+" (Plus sign).
0x0000001FAll All characters. Since all elements are enabled, there is no filtering. This a combination of Digit (| Uppercase | Lowercase | Punctuation | Miscellaneous).
0x00000020Plus Enables the use of the "FilterPlus" characters. The FilterPlus characters are added after any filtering.
0x00000021Numbers Digits plus the "FilterPlus" characters This is a combination of (Digit | Plus).

This enumeration lists the available character set filter elements. The Language environment can be narrowed by specifying Character Set filters. The name of each filter element indicates which category of characters it validates. This enumeration is attributes with the FlagsAttribute and its members can be combined (OR-ed) together.

The filters can have an effect either at zone level (by specifying the zone's OcrZone.CharacterFilters property), or globally, at image level (defined by the "Recognition.DefaultCharacterFilter" setting).

The way to set no filtering is to give the value OcrZoneCharacterFilters.All.

Characters of the document that are not part of the specified character set will either be rejected or will be recognized as a validated character with a similar shape. For instance, if only the English language has been selected and the document contains a letter "Capital A with acute", then the recognized output will be a letter "Capital A"

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Forms.Common; 
using Leadtools.Document.Writer; 
using Leadtools.WinForms; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
public void OcrAutoZoneExample() 
   // Create an image with some text in it 
   RasterImage image = new RasterImage(RasterMemoryFlags.Conventional, 320, 200, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0); 
   Rectangle imageRect = new Rectangle(0, 0, image.ImageWidth, image.ImageHeight); 
   IntPtr hdc = RasterImagePainter.CreateLeadDC(image); 
   using (Graphics g = Graphics.FromHdc(hdc)) 
      g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
      g.FillRectangle(Brushes.White, imageRect); 
      using (Font f = new Font("Arial", 20, FontStyle.Regular)) 
         g.DrawString("Normal line", f, Brushes.Black, 0, 0); 
      using (Font f = new Font("Courier New", 20, FontStyle.Regular)) 
         g.DrawString("Monospaced line", f, Brushes.Black, 0, 80); 
   string zonesFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyZones.xml"); 
   // 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); 
      // Create an OCR page 
      using (IOcrPage ocrPage = ocrEngine.CreatePage(image, OcrImageSharingMode.AutoDispose)) 
         // Show the zones, there should be no zones yet 
         ShowZones("Right after the page was created", ocrPage); 
         // Perform default AutoZoning on the page 
         // Show the zones, there should be two zones, one for each line 
         ShowZones("AutoZone with default parameters", ocrPage); 
         // Update the first zone manually 
         OcrZone ocrZone = ocrPage.Zones[0]; 
         ocrZone.ZoneType = OcrZoneType.Text; 
         ocrPage.Zones[0] = ocrZone; 
         // Show the zones 
         ShowZones("After updating the type of the first zone", ocrPage); 
         // Save the zones to a file and then clear them 
         // Show the zones, there should be no zones since we just cleared them 
         ShowZones("After calling save and clear", ocrPage); 
         // Re-load the zones 
         ShowZones("After re-loading the zones", ocrPage); 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
private void ShowZones(string message, IOcrPage ocrPage) 
   Console.WriteLine("Zones after {0}:", message); 
   foreach (OcrZone ocrZone in ocrPage.Zones) 
      int index = ocrPage.Zones.IndexOf(ocrZone); 
      Console.WriteLine("Zone index: {0}", index); 
      Console.WriteLine("  Id                  {0}", ocrZone.Id); 
      Console.WriteLine("  Bounds              {0}", ocrZone.Bounds); 
      Console.WriteLine("  ZoneType            {0}", ocrZone.ZoneType); 
      Console.WriteLine("  CharacterFilters:   {0}", ocrZone.CharacterFilters); 
   Console.WriteLine("Hit enter to continue"); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 

Target Platforms

Help Version 23.0.2024.4.19
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.