CogOCRMaxLineResult ClassCognex VisionPro 9.5
A Collection of CogOCRMaxPositionResults which represent the output/result of running the OCRMax tool.
Inheritance Hierarchy

System Object
  System MarshalByRefObject
    Cognex.VisionPro.Implementation CogObjectBase
      Cognex.VisionPro.Implementation CogSerializableObjectBase
        Cognex.VisionPro.Implementation CogReadOnlyCollection CogOCRMaxPositionResult 
          Cognex.VisionPro.OCRMax CogOCRMaxLineResult

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

[SerializableAttribute]
public class CogOCRMaxLineResult : CogReadOnlyCollection<CogOCRMaxPositionResult>, 
	ICogRecordConstructor

The CogOCRMaxLineResult type exposes the following members.

Constructors

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

  NameDescription
Public methodContains
Determines whether an element is in the collection.
(Inherited from CogReadOnlyCollection T .)
Public methodCopyTo
Copies the entire Collection to a compatible one-dimensional Array, starting at the specified index of the target array.
(Inherited from CogReadOnlyCollection 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 methodCreateResultGraphics
Creates a CogGraphicCollection which represents the result.
Public methodCreateTuneRecordFromResult
Returns a CogOCRMaxTuneRecord based on this result. The record can be corrected and then used to tune the the CogOCRMaxTool.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
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.)
Public methodGetClassifierLineResult
Returns a copy of the result of the Tool's classifier operation.
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 methodGetFieldingLineResult
Returns a copy of the result of the Tool's fielding operation.
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 )
Causes the list of items to show up in the property grid.
(Inherited from CogReadOnlyCollection T .)
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 methodGetSegmenterLineResult
Returns a copy of the result of the Tool's segmenter operation.
Public methodGetString 
Returns a string which represents this CogOCRMaxLineResult.
Public methodGetString(String)
Returns a string which represents this CogOCRMaxLineResult.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf
Searches the collection for the specified object and returns the zero-based index of the first occurrence.
(Inherited from CogReadOnlyCollection T .)
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.)
Public methodToArray
Calls CopyTo() and returns a new array which contains the members of this collection.
(Inherited from CogReadOnlyCollection T .)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Top
Fields

  NameDescription
Protected fieldmInnerList (Inherited from CogReadOnlyCollection T .)
Top
Properties

  NameDescription
Public propertyBinarizedLineImage
Return an image of the line of the characters after normalization, and binarization.
Public propertyCount
The number of elements contained in the Collection.
(Inherited from CogReadOnlyCollection T .)
Public propertyItem
Gets the element at the specified index.
(Inherited from CogReadOnlyCollection T .)
Public propertyLineImage
An image of the line of the characters.
Public propertyNormalizedLineImage
An image of the line of characters after normalization.
Public propertyResultString
The result string read by the OCRMax tool.
Public propertyStatus
The overall status of the result.
Public propertyUnknownCharacterMarker
Used to represent characters that could not be classified in the ResultString.
Top
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