CogOCRMaxFont ClassCognex VisionPro 9.7
A container of CogOCRMaxChars (character images and their associated character codes) used to train the OCRMax classifier.
Inheritance Hierarchy

System Object
  System MarshalByRefObject
    Cognex.VisionPro.Implementation CogObjectBase
      Cognex.VisionPro.Implementation CogSerializableObjectBase
        Cognex.VisionPro.Implementation CogSerializableChangedEventBase
          Cognex.VisionPro.Implementation CogSerializableCollectionBase CogOCRMaxChar 
            Cognex.VisionPro.OCRMax CogOCRMaxFont

Namespace: Cognex.VisionPro.OCRMax
Assembly: Cognex.VisionPro.OCRMax (in Cognex.VisionPro.OCRMax.dll) Version: 73.0.0.0
Syntax

[SerializableAttribute]
public class CogOCRMaxFont : CogSerializableCollectionBase<CogOCRMaxChar>, 
	IDeserializationCallback

The CogOCRMaxFont type exposes the following members.

Constructors

  NameDescription
Public methodCogOCRMaxFont 
Construct a default CogOCRMaxFont object.
Public methodCogOCRMaxFont(CogOCRMaxFont)
Constructs a deep copy of the supplied CogOCRMaxFont object.
Protected methodCogOCRMaxFont(SerializationInfo, StreamingContext)
Serialization constructor for CogOCRMaxFont.
Top
Methods

  NameDescription
Public methodAdd
Adds value to the end of the collection.
(Inherited from CogSerializableCollectionBase T .)
Public methodClear
Removes all objects from the collection.
(Inherited from CogSerializableCollectionBase T .)
Public methodContains
Returns true if value is in the collection
(Inherited from CogSerializableCollectionBase T .)
Public methodCopyTo
Copies the collection to an array
(Inherited from CogSerializableCollectionBase T .)
Public methodCreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExport
Save this font into a Cognex ".ocr" formatted font file on disk.
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Protected methodGetAttributes
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetClassName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetComponentName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetConverter
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetDefaultEvent
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetDefaultProperty
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEditor
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodGetObjectData
Implements the GetObjectData method of the ISerializable interface.
(Inherited from CogSerializableObjectBase.)
Protected methodGetProperties 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetProperties( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetPropertyOwner
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodImport
Load a Cognex ".ocr" formatted font file from disk.
Public methodIndexOf
Returns the index of value in the collection, or -1 if value is not in the collection.
(Inherited from CogSerializableCollectionBase T .)
Public methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Public methodInsert
Inserts the value at the specified index of the collection
(Inherited from CogSerializableCollectionBase T .)
Protected methodMemberwiseClone 
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodMemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject.)
Public methodMove
Moves an item from one position to another.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnChanged(Int64)
This method should be called internally whenever the object's state may have changed.
(Inherited from CogSerializableChangedEventBase.)
Protected methodOnChanged(CogChangedEventArgs)
This method may be called internally whenever a derived object's state may have changed and the derived object expresses this change via a derived CogChangedEventArgs class.
(Inherited from CogSerializableChangedEventBase.)
Protected methodOnCleared
Raises the Cleared event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnClearing
Called whenever the Font is about to be cleared.
(Overrides CogSerializableCollectionBase T  OnClearing .)
Public methodOnDeserialization
Called to force the Font to complete it's Deserialization process.
Protected methodOnInsertedItem
Raises the InsertedItem event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnInsertingItem
Called whenver a CogOCRMaxChar is about to be insterted into the Font.
(Overrides CogSerializableCollectionBase T  OnInsertingItem(Int32, Object).)
Protected methodOnMovedItem
Raises the MovedItem event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnMovingItem
Raises the MovingItem event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnRemovedItem
Called whenever a CogOCRMaxChar is removed from the Font.
(Overrides CogSerializableCollectionBase T  OnRemovedItem(Int32, Object).)
Protected methodOnRemovingItem
Raises the RemovingItem event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnReplacedItem
Raises the ReplacedItem event.
(Inherited from CogSerializableCollectionBase T .)
Protected methodOnReplacingItem
Called whenever a CogOCRMaxChar is being replaced.
(Overrides CogSerializableCollectionBase T  OnReplacingItem(Int32, Object, Object).)
Public methodRemove
Removes value from the collection
(Inherited from CogSerializableCollectionBase T .)
Public methodRemoveAt
Removes the element at the specified index.
(Inherited from CogSerializableCollectionBase T .)
Public methodResumeAndRaiseChangedEvent
Re-enables raising of the Changed event after SuspendChangedEvent has been called, and raises the Changed event if the ChangedEventSuspended count is reduced to zero and any changes were made while events were suspended. Must be called once for each call to SuspendChangedEvent.
(Inherited from CogSerializableChangedEventBase.)
Public methodSuspendChangedEvent
Temporarily suspends the raising of the Changed event. May be called more than once, and a corresponding call to ResumeAndRaiseChangedEvent must be made for each call to SuspendChangedEvent.
(Inherited from CogSerializableChangedEventBase.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Fields

  NameDescription
Public fieldStatic memberSfName
This bit will be set in the EventArgs of a Changed event every time the value returned by Name may have changed.
Protected fieldStatic memberSfNextSf
Top
Properties

  NameDescription
Public propertyChangedEventSuspended
If nonzero, indicates that the raising of the Changed event has been suspended. This value is incremented when SuspendChangedEvent is called and decremented when ResumeAndRaiseChangedEvent is called.
(Inherited from CogSerializableChangedEventBase.)
Public propertyCount
Gets the number of elements contained in the collection.
(Inherited from CogSerializableCollectionBase T .)
Public propertyHasChanged (Inherited from CogSerializableChangedEventBase.)
Protected propertyInnerList
Gets the internal List containing the list of elements.
(Inherited from CogSerializableCollectionBase T .)
Public propertyIsFixedSize
returns false
(Inherited from CogSerializableCollectionBase T .)
Public propertyIsReadOnly
Returns true if this collection is ReadOnly
(Inherited from CogSerializableCollectionBase T .)
Public propertyIsSynchronized (Inherited from CogSerializableCollectionBase T .)
Public propertyItem Int32 
Returns the T at index
(Inherited from CogSerializableCollectionBase T .)
Public propertyItem CogOCRMaxCharKey 
Protected propertyList
Gets an the IList interface of this collection.
(Inherited from CogSerializableCollectionBase T .)
Public propertyName
The name of the font.
Public propertyStateFlags
Returns the complete set of state flags supported on this object. The flags may be indexed by name as shown in the following C# code snippet: if (changedObject.StateFlags["Color"] & eventArgs.StateFlags) { ... }
(Inherited from CogSerializableChangedEventBase.)
Public propertySyncRoot (Inherited from CogSerializableCollectionBase T .)
Top
Events

  NameDescription
Public eventChanged
This event is raised when one or more parts of the object's state may have changed.
(Inherited from CogSerializableChangedEventBase.)
Public eventCleared
Raised after the collection is cleared.
(Inherited from CogSerializableCollectionBase T .)
Public eventClearing
Raised before the collection is cleared.
(Inherited from CogSerializableCollectionBase T .)
Public eventInsertedItem
Raised after an item is inserted.
(Inherited from CogSerializableCollectionBase T .)
Public eventInsertingItem
Raised before an item is inserted.
(Inherited from CogSerializableCollectionBase T .)
Public eventMovedItem
Raised after an item is moved to a new index.
(Inherited from CogSerializableCollectionBase T .)
Public eventMovingItem
Raised before an item is moved to a new index.
(Inherited from CogSerializableCollectionBase T .)
Public eventRemovedItem
Raised after an item is removed.
(Inherited from CogSerializableCollectionBase T .)
Public eventRemovingItem
Raised before an item is removed.
(Inherited from CogSerializableCollectionBase T .)
Public eventReplacedItem
Raised after an item is replaced.
(Inherited from CogSerializableCollectionBase T .)
Public eventReplacingItem
Raised before an item is replaced.
(Inherited from CogSerializableCollectionBase T .)
Top
Remarks

Note that a CogOCRMaxFont should never contain 'space' characters. The OCRMax Classifier does not classify space characters. Instead the classifier input (cf. the segmenter output) is responsible for deciding if a particular character is a space. The classifier simply "passes through" space characters and their associated scores.

Note that a CogOCRMaxFont should never contain CogOCRMaxChars that have their Key.CharacterCode set to the special "Unknown" character code (0xF800).

Note that a CogOCRMaxChar reference can only be a member of a single CogOCRMaxFont.

Adding a CogOCRMaxChar to a CogOCRMaxFont will set the CogOCRMaxChar.Key to a value that is unique amongst all the CogOCRMaxChars in the CogOCRMaxFont.

The Font's indices are maintained the same way as in most standard .NET Collections. Meaning, the Add() method will append new CogOCRMaxChars to the end of the Font (at the highest index) and the order is maintained. In other words the, CogOCRMaxChars in the Font are not sorted by index in any way.

Examples

Imports System.Drawing
Imports Cognex.VisionPro
Imports Cognex.VisionPro.OCRMax

Module CogOCRMaxExample

  Sub Main()

    Dim OCRMaxTool As New CogOCRMaxTool()

    ' Load an image containing the text to read.
    Dim bmp As New Bitmap(System.Environment.GetEnvironmentVariable("VPRO_ROOT") & "\images\alphanumbers.bmp")

    Dim image As New CogImage8Grey(bmp)

    ' Create a rectangle that surrounds the text 
    ' "ABCDEFGHIJKLMNOPQRSTUVWXYZ" in the image.
    Dim rect As New CogRectangleAffine()
    rect.SetOriginLengthsRotationSkew(340, 748, 1010, 93, 0, 0)

    ' Set the image and search region of the tool.
    OCRMaxTool.InputImage = image
    OCRMaxTool.Region = rect

    ' Segment the characters in the image.
    OCRMaxTool.Run()

    If OCRMaxTool.RunStatus.Result <> CogToolResultConstants.Accept OrElse OCRMaxTool.LineResult.Count <> 26 Then
      Console.WriteLine("Initial segmentation failed. " + OCRMaxTool.RunStatus.Message)
      Return
    End If

    ' Get an array of Unicode UTF-32 character codes
    ' which represent a string of all the letters in the 
    ' english alphabet.
    Dim alphabetString As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Dim alphabetCharCodes As Integer() = CogOCRMaxChar.GetCharCodesFromString(alphabetString)

    ' Label each segmented character with the correct
    ' character code and add it to the classifier's font.
    For i As Integer = 0 To OCRMaxTool.LineResult.Count - 1
      Dim c As CogOCRMaxChar = OCRMaxTool.LineResult(i).GetCharacter()
      c.CharacterCode = alphabetCharCodes(i)
      OCRMaxTool.Classifier.Font.Add(c)
    Next

    Try
      ' Train the classifier based on the font.
      OCRMaxTool.Classifier.Train()
    Catch ex As Exception
      Console.WriteLine("Failed to train classifier characters: " & ex.Message)
    End Try

    ' Run the (now trained) tool again.
    OCRMaxTool.Run()

    If OCRMaxTool.RunStatus.Result <> CogToolResultConstants.Accept Then
      Console.WriteLine("OCRMax tool failed: " + OCRMaxTool.RunStatus.Message)
      Return
    End If

    If OCRMaxTool.LineResult.Status <> CogOCRMaxLineResultStatusConstants.Read Then
      Console.WriteLine("OCRMax tool failed to read the line of text.")
      Return
    End If

    ' Print out the read string.
    Console.WriteLine("OCRMax Tool read the string: " + OCRMaxTool.LineResult.ResultString)
  End Sub
End Module
using System;
using System.Drawing;
using Cognex.VisionPro;
using Cognex.VisionPro.OCRMax;

class CogOCRMaxExample
{
  static void Main()
  {
    CogOCRMaxTool OCRMaxTool = new CogOCRMaxTool();

    // Load an image containing the text to read.
    Bitmap bmp = new Bitmap(
      System.Environment.GetEnvironmentVariable("VPRO_ROOT") +
      @"\images\alphanumbers.bmp");

    CogImage8Grey image = new CogImage8Grey(bmp);

    // Create a rectangle that surrounds the text  
    // "ABCDEFGHIJKLMNOPQRSTUVWXYZ" in the image.
    CogRectangleAffine rect = new CogRectangleAffine();
    rect.SetOriginLengthsRotationSkew(340, 748, 1010, 93, 0, 0);

    // Set the image and search region of the tool.
    OCRMaxTool.InputImage = image;
    OCRMaxTool.Region = rect;

    // Segment the characters in the image.
    OCRMaxTool.Run();

    if (OCRMaxTool.RunStatus.Result != CogToolResultConstants.Accept ||
        OCRMaxTool.LineResult.Count != 26)
    {
      Console.WriteLine(
        "Initial segmentation failed. " + OCRMaxTool.RunStatus.Message);
      return;
    }

    // Get an array of Unicode UTF-32 character codes 
    // which represent a string of all the letters in the  
    // english alphabet. 
    string alphabetString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int[] alphabetCharCodes =
      CogOCRMaxChar.GetCharCodesFromString(alphabetString);

    // Label each segmented character with the correct 
    // character code and add it to the classifier's font. 
    for (int i = 0; i < OCRMaxTool.LineResult.Count; i++)
    {
      CogOCRMaxChar c = OCRMaxTool.LineResult[i].GetCharacter();
      c.CharacterCode = alphabetCharCodes[i];
      OCRMaxTool.Classifier.Font.Add(c);
    }

    try
    {
      // Train the classifier based on the font.
      OCRMaxTool.Classifier.Train();
    }
    catch (Exception ex)
    {
      Console.WriteLine(
        "Failed to train classifier characters: " + ex.Message);
    }

    // Run the (now trained) tool again.
    OCRMaxTool.Run();

    if (OCRMaxTool.RunStatus.Result != CogToolResultConstants.Accept)
    {
      Console.WriteLine("OCRMax tool failed: " + OCRMaxTool.RunStatus.Message);
      return;
    }

    if (OCRMaxTool.LineResult.Status != CogOCRMaxLineResultStatusConstants.Read)
    {
      Console.WriteLine("OCRMax tool failed to read the line of text.");
      return;
    }

    // Print out the read string.
    Console.WriteLine("OCRMax Tool read the string: " + OCRMaxTool.LineResult.ResultString);
  }
}
See Also