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
The CogOCRMaxFont type exposes the following members.
| Name | Description | |
|---|---|---|
| CogOCRMaxFont |
Construct a default CogOCRMaxFont object.
| |
| CogOCRMaxFont(CogOCRMaxFont) |
Constructs a deep copy of the supplied CogOCRMaxFont object.
| |
| CogOCRMaxFont(SerializationInfo, StreamingContext) |
Serialization constructor for CogOCRMaxFont.
|
| Name | Description | |
|---|---|---|
| Add |
Adds value to the end of the collection.
(Inherited from CogSerializableCollectionBase T .) | |
| Clear |
Removes all objects from the collection.
(Inherited from CogSerializableCollectionBase T .) | |
| Contains |
Returns true if value is in the collection
(Inherited from CogSerializableCollectionBase T .) | |
| CopyTo |
Copies the collection to an array
(Inherited from CogSerializableCollectionBase T .) | |
| CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) | |
| Equals | (Inherited from Object.) | |
| Export |
Save this font into a Cognex ".ocr" formatted font file on disk.
| |
| Finalize | Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
| GetAttributes |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetClassName |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetComponentName |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetConverter |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetDefaultEvent |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetDefaultProperty |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetEditor |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetEvents |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetEvents( Attribute ) |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
| GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) | |
| GetObjectData |
Implements the GetObjectData method of the ISerializable interface.
(Inherited from CogSerializableObjectBase.) | |
| GetProperties |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetProperties( Attribute ) |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetPropertyOwner |
Implements the corresponding member of the ICustomTypeDescriptor interface.
May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| Import |
Load a Cognex ".ocr" formatted font file from disk.
| |
| IndexOf |
Returns the index of value in the collection, or -1 if value
is not in the collection.
(Inherited from CogSerializableCollectionBase T .) | |
| InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) | |
| Insert |
Inserts the value at the specified index of the collection
(Inherited from CogSerializableCollectionBase T .) | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) | |
| Move |
Moves an item from one position to another.
(Inherited from CogSerializableCollectionBase T .) | |
| OnChanged(Int64) |
This method should be called internally whenever the object's state may
have changed.
(Inherited from CogSerializableChangedEventBase.) | |
| OnChanged(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.) | |
| OnCleared |
Raises the Cleared event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnClearing |
Called whenever the Font is about to be cleared.
(Overrides CogSerializableCollectionBase T OnClearing .) | |
| OnDeserialization |
Called to force the Font to complete it's Deserialization process.
| |
| OnInsertedItem |
Raises the InsertedItem event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnInsertingItem |
Called whenver a CogOCRMaxChar is about to be insterted into the Font.
(Overrides CogSerializableCollectionBase T OnInsertingItem(Int32, Object).) | |
| OnMovedItem |
Raises the MovedItem event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnMovingItem |
Raises the MovingItem event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnRemovedItem |
Called whenever a CogOCRMaxChar is removed from the Font.
(Overrides CogSerializableCollectionBase T OnRemovedItem(Int32, Object).) | |
| OnRemovingItem |
Raises the RemovingItem event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnReplacedItem |
Raises the ReplacedItem event.
(Inherited from CogSerializableCollectionBase T .) | |
| OnReplacingItem |
Called whenever a CogOCRMaxChar is being replaced.
(Overrides CogSerializableCollectionBase T OnReplacingItem(Int32, Object, Object).) | |
| Remove |
Removes value from the collection
(Inherited from CogSerializableCollectionBase T .) | |
| RemoveAt |
Removes the element at the specified index.
(Inherited from CogSerializableCollectionBase T .) | |
| ResumeAndRaiseChangedEvent |
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.) | |
| SuspendChangedEvent |
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.) | |
| ToString | (Inherited from Object.) |
| Name | Description | |
|---|---|---|
| SfName |
This bit will be set in the EventArgs of a Changed event every time the
value returned by Name may have changed.
| |
| SfNextSf |
| Name | Description | |
|---|---|---|
| ChangedEventSuspended |
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.) | |
| Count |
Gets the number of elements contained in the collection.
(Inherited from CogSerializableCollectionBase T .) | |
| HasChanged | (Inherited from CogSerializableChangedEventBase.) | |
| InnerList |
Gets the internal List containing the list of elements.
(Inherited from CogSerializableCollectionBase T .) | |
| IsFixedSize |
returns false
(Inherited from CogSerializableCollectionBase T .) | |
| IsReadOnly |
Returns true if this collection is ReadOnly
(Inherited from CogSerializableCollectionBase T .) | |
| IsSynchronized | (Inherited from CogSerializableCollectionBase T .) | |
| Item Int32 |
Returns the T at index (Inherited from CogSerializableCollectionBase T .) | |
| Item CogOCRMaxCharKey | ||
| List |
Gets an the IList interface of this collection.
(Inherited from CogSerializableCollectionBase T .) | |
| Name |
The name of the font.
| |
| StateFlags |
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.) | |
| SyncRoot | (Inherited from CogSerializableCollectionBase T .) |
| Name | Description | |
|---|---|---|
| Changed |
This event is raised when one or more parts of the object's state may
have changed.
(Inherited from CogSerializableChangedEventBase.) | |
| Cleared |
Raised after the collection is cleared.
(Inherited from CogSerializableCollectionBase T .) | |
| Clearing |
Raised before the collection is cleared.
(Inherited from CogSerializableCollectionBase T .) | |
| InsertedItem |
Raised after an item is inserted.
(Inherited from CogSerializableCollectionBase T .) | |
| InsertingItem |
Raised before an item is inserted.
(Inherited from CogSerializableCollectionBase T .) | |
| MovedItem |
Raised after an item is moved to a new index.
(Inherited from CogSerializableCollectionBase T .) | |
| MovingItem |
Raised before an item is moved to a new index.
(Inherited from CogSerializableCollectionBase T .) | |
| RemovedItem |
Raised after an item is removed.
(Inherited from CogSerializableCollectionBase T .) | |
| RemovingItem |
Raised before an item is removed.
(Inherited from CogSerializableCollectionBase T .) | |
| ReplacedItem |
Raised after an item is replaced.
(Inherited from CogSerializableCollectionBase T .) | |
| ReplacingItem |
Raised before an item is replaced.
(Inherited from CogSerializableCollectionBase T .) |
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.
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 Moduleusing 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); } }