CogOCRMaxClassifier ClassCognex VisionPro 9.8
Classification is the second main step in performing OCRMax. Classification takes in a CogOCRMaxChar produced by the segmenter and returns the best matching character, the score of that best matching character, and the confidence of that best matching character. By classifying all of the segmented characters in a line of text, the classifier determines the result string for the whole line. See the OCRMax Theory Guide for more information.
Inheritance Hierarchy

System Object
  System MarshalByRefObject
    Cognex.VisionPro.Implementation CogObjectBase
      Cognex.VisionPro.Implementation CogSerializableObjectBase
        Cognex.VisionPro.Implementation CogSerializableChangedEventBase
          Cognex.VisionPro.OCRMax CogOCRMaxClassifier

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

[SerializableAttribute]
public class CogOCRMaxClassifier : CogSerializableChangedEventBase, 
	IDeserializationCallback

The CogOCRMaxClassifier type exposes the following members.

Constructors

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

  NameDescription
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 methodExecute(CogOCRMaxChar, CogOCRMaxClassifierRunParams)
Classify a single character. The input CogOCRMaxChar contains an image of the character, as well as a Metrics property which define the character's mark rectangle and cell rectangle. Typically the input CogOCRMaxChar.CharacterCode is set to Unknown because the character has not yet been classified.
Public methodExecute(IEnumerable CogOCRMaxChar , CogOCRMaxClassifierRunParams)
Classify a collection of characters.
Public methodExecute(CogOCRMaxClassifierRunParams, IList CogOCRMaxSegmenterPositionResult )
Classify the line of segmented characters contained in the CogOCRMaxSegmenterLineResult.
Public methodExecute(CogOCRMaxSegmenterLineResult, CogOCRMaxClassifierRunParams)
Classify the line of segmented characters contained in the CogOCRMaxSegmenterLineResult.
Public methodExecute(CogOCRMaxSegmenterPositionResult, CogOCRMaxClassifierRunParams)
Classify a single segmented character.
Public methodExecute(CogOCRMaxChar, CogOCRMaxClassifierRunParams, CogOCRMaxSwapCharSet)
Classify a single character. The input CogOCRMaxChar contains an image of the character, as well as a Metrics property which define the character's mark rectangle and cell rectangle. Typically the input CogOCRMaxChar.CharacterCode is set to Unknown because the character has not yet been classified.
Public methodExecute(IEnumerable CogOCRMaxChar , CogOCRMaxClassifierRunParams, CogOCRMaxSwapCharSet)
Classify a collection of characters.
Public methodExecute(CogOCRMaxClassifierRunParams, CogOCRMaxSwapCharSet, IList CogOCRMaxSegmenterPositionResult )
Classify the line of segmented characters contained in the CogOCRMaxSegmenterLineResult.
Public methodExecute(CogOCRMaxSegmenterLineResult, CogOCRMaxClassifierRunParams, CogOCRMaxSwapCharSet)
Classify the line of segmented characters contained in the CogOCRMaxSegmenterLineResult.
Public methodExecute(CogOCRMaxSegmenterPositionResult, CogOCRMaxClassifierRunParams, CogOCRMaxSwapCharSet)
Classify a single segmented character.
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 methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
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.)
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.)
Public methodOnDeserialization
Called when to complete the deserialziation of the CogOCRMaxClassifier.
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.)
Public methodTrain
Trains the classifier using the current font and train params.
Public methodUntrain
Untrains the classifier.
Top
Fields

  NameDescription
Public fieldStatic memberSfFont
This bit will be set in the EventArgs of a Changed event every time the value returned by Font may have changed.
Protected fieldStatic memberSfNextSf
Public fieldStatic memberSfTimeout
This bit will be set in the EventArgs of a Changed event every time the value returned by Timeout may have changed.
Public fieldStatic memberSfTimeoutEnabled
This bit will be set in the EventArgs of a Changed event every time the value returned by TimeoutEnabled may have changed.
Public fieldStatic memberSfTrained
This bit will be set in the EventArgs of a Changed event every time the value returned by Trained may have changed.
Public fieldStatic memberSfTrainOnRun
This bit will be set in the EventArgs of a Changed event every time the value returned by TrainOnRun may have changed.
Public fieldStatic memberSfTrainParams
This bit will be set in the EventArgs of a Changed event every time the value returned by TrainParams may have changed.
Public fieldStatic memberSfTrainTimeout
This bit will be set in the EventArgs of a Changed event every time the value returned by TrainTimeout may have changed.
Public fieldStatic memberSfTrainTimeoutEnabled
This bit will be set in the EventArgs of a Changed event every time the value returned by TrainTimeoutEnabled may have changed.
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 propertyFont
Contains the CogOCRMaxChars (images of individual characters) used to train the classifier.
Public propertyHasChanged (Inherited from CogSerializableChangedEventBase.)
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 propertyTimeout
Gets or sets the timeout for running the classifier in milliseconds.
Public propertyTimeoutEnabled
Enables the timeout for the classifier.
Public propertyTrained
The classifier is a trained operator. This property reflects whether or not the classifier is in a trained state.
Public propertyTrainOnRun
Controls the classifier's execute behavior when the classifier is not trained.
Public propertyTrainParams
Parameters which control how the classifier is trained. Changing the train params of a trained classifier will cause it to become untrained.
Public propertyTrainTimeout
Gets or sets the timeout for classifier training in milliseconds.
Public propertyTrainTimeoutEnabled
Enables the timeout for classifier training.
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.)
Top
Remarks

CogOCRMaxChar objects each contain an Image of the character as well as that character's Key and Metrics. The Key contains the character's character code; a Unicode UTF-32 code point which determines which 'letter' the CogOCRMaxChar corresponds to. The Metrics contain two regions (the mark rectangle and the cell rectangle) which define the location of the character in the image. The mark rectangle of a character is a tight bounding box enclosing all of foreground (e.g. ink) pixels in the character image. The cell rectangle is a bounding box that encloses not only all of the foreground (e.g. ink) pixels of a character image, but also typically additional padding region. Cell rectangles are typically height of the full line of text containing the character. Ideally, all of the cell rectangles in a line of text touch their adjacent neighbors. The CogOCRMaxChar class contains additional information as well, but the classifier only considers the rectified image, its mark rectangle, its cell rectangle, and the 32-bit character code.

The run-time character rectified images don't have to be exactly the same as the train-time character rectified images - in other words, the classifier should handle slight rotation, arbitrary x-scale and y-scale, and reasonable variation in terms of character texture and background texture.

In order to run the classifier it must first be trained. The OCRMax Classifier is trained by adding one or more examples of CogOCRMaxChars for each possible run-time character to the Classifier's Font. The OCRMax Classifier determines the character of the input CogOCRMaxChar by comparing its image to the training instances and finding the best match.

Handling Scale Variation by Resampling to Fixed Size:

The OCRMax Classifier is designed to handle x-scale/y-scale/uniform-scale/aspect variations in the run-time character in the rectified image. The OCRMax Classifier always resamples each rectified image to a predetermined size (the same resampled size is used for both train-time rectified images and run-time rectified images).

Note that the classifier can be set to rescale while maintaining the rectified image's aspect ratio. In this case each character can be resampled to a different width, although they will all be resampled to the same height.

Confidence/Confusion:

The OCRMax Classifier determines not only the classification (character code/instance) of the run-time rectified image, but it also reports the score of that classification and the confidence of that classification. The score is an indication of the closeness of the match to the training instances. The confidence is computed as the difference between the score of the classification (the highest scoring training instance) and the score of the next-highest classification (the highest scoring training instance from a different class). The OCRMax Classifier result includes a status (Read, Confused, or Failed) indicating the quality of the result:

The status is Read if its score satisfies the accept threshold and the confidence score satisfies the confidence threshold.

The status is Confused if the score satisfies the accept threshold but either (a) the confidence score does not satisfy the confidence threshold, or (b) a classification validation check does not pass.

The classification validation check attempts to verify that the highest scoring candidate is the correct classification. If this validation fails, the classifier result is marked as Confused, and the confidence score is set to 0. The result of this validation does not affect the result score.

When the result is Confused, the confusionExplanation member of the classifier result indicates whether it was due to the confidence score being too low, or due to a failure of the classification validation check.

Note: If the classifier has only 1 training character, the confidence score will be set to the score and the confusionCharacter will be default constructed.

The status is Failed if the score does not satisfy the accept threshold.

Note: If the highest scoring character does not satisfy the accept threshold, then the confidence score will be set to 0 and the alternative character vector will be empty, and the confusion character will be a default constructed character.

In addition to determining the classification, the score, and the confidence score, the OCRMax Classifier also reports a set of alternative classifications. The alternative classifications are all of the classes which induce sufficiently high scores. The confusion character is defined to be the highest scoring alternative character that is not a swap character of the highest scoring character. There will always be at least one alternative character/confusion character so long as the highest scoring character met the accept threshold and so long as there is at least one other (nonswap) class with nonzero score. Note that the alternative classifications are computed in a more sophisticated manner than simplify finding all classifications which induce scores satisfying the accept threshold. Instead, the alternative classifications are computed as any class which induced a score satisfying the following alternative score threshold:

"(the lowest score that is greater than or equal to the accept threshold) - (confidence threshold)" plus one different character more than that.

The alternative characters are sorted in order of decreasing score.

Swap Characters:

Note that the OCRMax Classifier optionally takes a swap character set (CogOCRMaxSwapCharSet) as input. If a swap character set is specified, then the confidence score is defined as the difference between the score of the highest scoring classification and the score of the next-highest classification which is not swappable with the highest scoring classification.

Scale Filters:

The OCRMax Classifier allows the user to optionally specify x-scale/y-scale filter ranges, which specify the acceptable scale factors between the train-time character mark rectangles and the run-time character mark rectangles. Only classes/instances that satisfy the scale constraints are compared against the rectified image.

Handling Spaces:

The OCRMax Classifier handles space characters differently from nonspace characters. In particular, users specify whether input characters are to be classified as spaces.

The current classifier behavior is to pass through all space characters with the specified score, with no alternative characters, and with the confidence score set to be equal to the score.

Notes:

The OCRMax Classifier analyzes each rectified image's character cell rectangle with respect to the rectified image's character mark rectangle. The classifier algorithm expects the mark rectangle to be relatively accurate and it expects the cell rectangle to be less accurate. Consequently, the classifier algorithm, for the most part, ignores the pixels in between the rectified image's character cell rectangle and the rectified image's mark rectangle. The classifier algorithm mainly considers the size and position of the cell rectangle window. The classifier algorithm requires that the cell rectangle be specified for every training/runtime character.

See Also