System MarshalByRefObject
Cognex.VisionPro.Implementation CogObjectBase
Cognex.VisionPro.Implementation CogSerializableObjectBase
Cognex.VisionPro.Implementation CogSerializableChangedEventBase
Cognex.VisionPro.OCRMax CogOCRMaxChar
Namespace: Cognex.VisionPro.OCRMax
Assembly: Cognex.VisionPro.OCRMax (in Cognex.VisionPro.OCRMax.dll) Version: 69.0.0.0
The CogOCRMaxChar type exposes the following members.
| Name | Description | |
|---|---|---|
| CogOCRMaxChar |
Construct a default CogOCRMaxChar object.
| |
| CogOCRMaxChar(CogOCRMaxChar) |
Constructs a deep copy of the supplied CogOCRMaxChar object.
| |
| CogOCRMaxChar(SerializationInfo, StreamingContext) |
Serialization constructor for CogOCRMaxChar.
|
| Name | Description | |
|---|---|---|
| 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.) | |
| 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.) | |
| GetCharCodeFromString(String) |
Returns the UTF 32-bit charcode that represents the letter in the input
string.
| |
| GetCharCodeFromString(String, String) |
Returns the UTF 32-bit charcode that represents the letter in the input
string.
| |
| GetCharCodesFromString(String) |
Returns an array of UTF 32-bit character codes that represent the input
string.
| |
| GetCharCodesFromString(String, String) |
Returns an array of UTF 32-bit character codes that represent the input
string.
| |
| 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.) | |
| GetString |
Returns a string which represents this CogOCRMaxChar.
| |
| GetString(String) |
Returns a string which represents this CogOCRMaxChar.
| |
| GetStringFromCharCode |
Returns the String representation of the UTF 32-bit charCode.
| |
| GetStringFromCharCodes |
Returns the String representation of the UTF 32-bit character codes.
| |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) | |
| 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.) | |
| 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.) | |
| 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 | |
|---|---|---|
| SfCharacterCode |
This bit will be set in the EventArgs of a Changed event every time the
value returned by CharacterCode may have changed.
| |
| SfFont |
This bit will be set in the EventArgs of a Changed event every time the
value returned by Font may have changed.
| |
| SfGetString |
This bit will be set in the EventArgs of a Changed event every time the
value returned by GetString may have changed.
| |
| SfKey |
This bit will be set in the EventArgs of a Changed event every time the
value returned by Key may have changed.
| |
| SfNextSf | ||
| SfPolarity |
This bit will be set in the EventArgs of a Changed event every time the
value returned by Polarity may have changed.
|
| Name | Description | |
|---|---|---|
| BinarizedImage |
The Binarized image for this character.
| |
| 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.) | |
| CharacterCode |
The character code, which is a Unicode UTF-32 code point. This can be
set to any Int32 value even though not all Int32 values are valid UTF-32
code points.
| |
| Font |
A reference to the CogOCRMaxFont of which this character is a member.
| |
| HasChanged | (Inherited from CogSerializableChangedEventBase.) | |
| Image |
A Rectified Image of the character. A Rectified Image is an image of the
character where the character is neither rotated nor skewed
| |
| Invert |
The invert value used to binarize the normalized image.
| |
| Key |
The key for this character. The key contains information that uniquely
identifies this character from other characters when it the CogOCRMaxChar
is a member of a CogOCRMaxFont
| |
| Metrics |
The metrics for this character.
| |
| NormalizedImage |
The Normalized image for this character.
| |
| Polarity |
The Polarity of the character.
| |
| 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.) | |
| Threshold |
The threshold value used to binarize the normalized image.
|
| Name | Description | |
|---|---|---|
| Changed |
This event is raised when one or more parts of the object's state may
have changed.
(Inherited from CogSerializableChangedEventBase.) |
The CogOCRMaxChar object contains an Image of the character as well as the character's Key and Metrics. The character code is a 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 where in the image the character is located. The CogOCRMaxChar class contains additional information as well, but the primary information about a character is contained within the rectified image, its mark rectangle, its cell rectangle, and the 32-bit character code.
Users are not typically expected to create instances of CogOCRMaxChar directly. Instances of CogOCRMaxChar are usually created by calling the GetCharacter() method of a CogOCRMaxPositionResult.
The CogOCRMaxChar.CharacterCode may be set to a special unknown character code (0xF800) to indicate that the character code is 'Unknown'.
The CogOCRMaxChar class also appears as the output of CogOCRMaxSegmenter, the input to CogOCRMaxClassifier, and the members of a CogOCRMaxFont.
Adding a CogOCRMaxChar to a CogOCRMaxFont will cause the CogOCRMaxChar's Key to be automatically replaced by a new CogOCRMaxCharKey to ensure that the Key's Instance number is unique.
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); } }