OCROptions Object

Applies to TestComplete 15.47, last modified on January 20, 2023
This object is provided by the legacy OCR plugin. In version 12.60, the plugin was replaced with the new Optical Character Recognition plugin powered by Google Cloud Vision API. To learn more, see Optical Character Recognition.
The legacy OCR plugin was removed from TestComplete in version 12.60. If you need to use objects, methods, and properties provided by the legacy plugin with this version of TestComplete, please contact our Customer Care team. The legacy OCR plugin was restored in TestComplete version 14.0. To use the objects, methods, and properties with this or later TestComplete version, you need to install and enable the plugin manually.

Description

The OCROptions object is used to configure settings that affect how optical character recognition in the visible area of the onscreen object will be performed. To get the OCROptions object, call the OCRObject.CreateOptions method.

Members

Example

The following code snippet creates an OCROptions object that contains the default character recognition settings and then posts those default settings to the test log.

JavaScript, JScript

function OCROptionsSample()
{
  var OnScreenObj, Rect, OCRObj, OCROptions, Info, Fonts, Count;
  …

  // Obtains an image of an on-screen object
  Rect = OnScreenObj.Picture();
  // Creates an OCR object
  OCRObj = OCR.CreateObject(Rect);
  // Creates an OCROptions object that stores the default character recognition settings
  OCROptions = OCRObj.DefaultOptions;

  // Obtains the default settings and posts them to the test log
  Info = "Active recognition set: " + OCROptions.ActiveRecognitionSet + "\r\n"+
         "Grayscale binarization: " + OCROptions.GrayScaleBinarization + "\r\n" +
         "Binarization threshold: " + OCROptions.BinarizationThreshold + "\r\n" +
         "Recognition autorejection: " + OCROptions.RecognitionRejectionAuto + "\r\n" +
         "Recognition rejection threshold: " + OCROptions.RecognitionRejection + "\r\n" +
         "Exact search is used: " + OCROptions.ExactSearch + "\r\n" +
         "Search accuracy threshold: " + OCROptions.SearchAccuracy + "\r\n" +
         "Skip fragmentation: " + OCROptions.SkipFragmentation;
  Log.Message("Character Recognition Default Settings", Info);
  // Obtains the collection of fonts used for character recognition
  // And posts them to the test log
  Fonts = OCROptions.Fonts;
  Count = Fonts.Count;
  Log.AppendFolder("Fonts used for character recognition:");
  for (var i = 0; i < Count; i++)
    Log.Message(Fonts.Item(i).Name);
  Log.PopLogFolder();

}

Python

def OCROptionsSample():
  # ...
  # Obtains an image of an on-screen object 
  Rect = OnScreenObj.Picture()
  # Creates an OCR object 
  OCRObj = OCR.CreateObject(Rect)
  # Creates an OCROptions object that stores the default character recognition settings 
  OCROptions = OCRObj.DefaultOptions
  # Obtains the default settings and posts them to the test log 
  Info = "Active recognition set: " + str(OCROptions.ActiveRecognitionSet) + "\r\n" + "Grayscale binarization: " + str(OCROptions.GrayScaleBinarization) + "\r\n" + "Binarization threshold: " + str(OCROptions.BinarizationThreshold) + "\r\n" + "Recognition autorejection: " + str(OCROptions.RecognitionRejectionAuto) + "\r\n" + "Recognition rejection threshold: " + str(OCROptions.RecognitionRejection) + "\r\n" + "Exact search is used: " + str(OCROptions.ExactSearch) + "\r\n" + "Search accuracy threshold: " + str(OCROptions.SearchAccuracy) + "\r\n" + "Skip fragmentation: " + str(OCROptions.SkipFragmentation)
  Log.Message("Character Recognition Default Settings", Info)
  # Obtains the collection of fonts used for character recognition 
  # And posts them to the test log 
  Fonts = OCROptions.Fonts
  Count = Fonts.Count
  Log.AppendFolder("Fonts used for character recognition:")
  for i in range(0, Count):
    Log.Message(Fonts.Item[i].Name)
  Log.PopLogFolder()

VBScript

Sub OCROptionsSample

  …

  ' Obtains an image of an on-screen object
  Set Rect = OnScreenObj.Picture
  ' Creates an OCR object
  Set OCRObj = OCR.CreateObject(Rect)
  ' Creates an OCROptions object that stores the default character recognition settings
  Set OCROptions = OCRObj.DefaultOptions

  ' Obtains the default settings and posts them to the test log
  Info = "Active recognition set: " & OCROptions.ActiveRecognitionSet & VbCrLf & _
         "Grayscale binarization: " & OCROptions.GrayScaleBinarization & VbCrLf & _
         "Binarization threshold: " & OCROptions.BinarizationThreshold & VbCrLf & _
         "Recognition autorejection: " & OCROptions.RecognitionRejectionAuto & VbCrLf & _
         "Recognition rejection threshold: " & OCROptions.RecognitionRejection & VbCrLf & _
         "Exact search is used: " & OCROptions.ExactSearch & VbCrLf & _
         "Search accuracy threshold: " & OCROptions.SearchAccuracy & VbCrLf & _
         "Skip fragmentation: " & OCROptions.SkipFragmentation
  Call Log.Message("Character Recognition Default Settings", Info)
  ' Obtains the collection of fonts used for character recognition
  ' And posts them to the test log
  Set Fonts = OCROptions.Fonts
  Count = Fonts.Count
  Log.AppendFolder "Fonts used for character recognition:"
  For i = 0 To Count - 1
    Log.Message Fonts.Item(i).Name
  Next
  Log.PopLogFolder

End Sub

DelphiScript

procedure OCROptionsSample();
var
  OnScreenObj, Rect, OCRObj, OCROptions, Fonts : OleVariant;
  Info : string;
  i, Count : integer;
begin
  …

  // Obtains an image of an on-screen object
  Rect := OnScreenObj.Picture;
  // Creates an OCR object
  OCRObj := OCR.CreateObject(Rect);
  // Creates an OCROptions object that stores the default character recognition settings
  OCROptions := OCRObj.DefaultOptions;

  // Obtains the default settings and posts them to the test log
  Info := 'Active recognition set: ' + aqConvert.IntToStr(OCROptions.ActiveRecognitionSet) + #13#10+
         'Grayscale binarization: ' + aqConvert.VarToStr(OCROptions.GrayScaleBinarization) + #13#10 +
         'Binarization threshold: ' + aqConvert.IntToStr(OCROptions.BinarizationThreshold) + #13#10 +
         'Recognition autorejection: ' + aqConvert.VarToStr(OCROptions.RecognitionRejectionAuto) + #13#10 +
         'Recognition rejection threshold: ' + aqConvert.FloatToStr(OCROptions.RecognitionRejection) + #13#10 +
         'Exact search is used: ' + aqConvert.VarToStr(OCROptions.ExactSearch) + #13#10 +
         'Search accuracy threshold: ' + aqConvert.FloatToStr(OCROptions.SearchAccuracy) + #13#10 +
         'Skip fragmentation: ' + aqConvert.VarToStr(OCROptions.SkipFragmentation);
  Log.Message('Character Recognition Default Settings', Info);
  // Obtains the collection of fonts used for character recognition
  // And posts them to the test log
  Fonts := OCROptions.Fonts;
  Count := Fonts.Count;
  Log.AppendFolder('Fonts used for character recognition:');
  for i := 0 to Count - 1 do
    Log.Message(Fonts.Item[i].Name);
  Log.PopLogFolder;

end;

C++Script, C#Script

function OCROptionsSample()
{
  var OnScreenObj, Rect, OCRObj, OCROptions, Info, Fonts, Count;
  …

  // Obtains an image of an on-screen object
  Rect = OnScreenObj["Picture"]();
  // Creates an OCR object
  OCRObj = OCR["CreateObject"](Rect);
  // Creates an OCROptions object that stores the default character recognition settings
  OCROptions = OCRObj["DefaultOptions"];

  // Obtains the default settings and posts them to the test log
  Info = "Active recognition set: " + OCROptions["ActiveRecognitionSet"] + "\r\n"+
         "Grayscale binarization: " + OCROptions["GrayScaleBinarization"] + "\r\n" +
         "Binarization threshold: " + OCROptions["BinarizationThreshold"] + "\r\n" +
         "Recognition autorejection: " + OCROptions["RecognitionRejectionAuto"] + "\r\n" +
         "Recognition rejection threshold: " + OCROptions["RecognitionRejection"] + "\r\n" +
         "Exact search is used: " + OCROptions["ExactSearch"] + "\r\n" +
         "Search accuracy threshold: " + OCROptions["SearchAccuracy"] + "\r\n" +
         "Skip fragmentation: " + OCROptions["SkipFragmentation"];
  Log.Message("Character Recognition Default Settings", Info);
  // Obtains the collection of fonts used for character recognition
  // And posts them to the test log
  Fonts = OCROptions["Fonts"];
  Count = Fonts["Count"];
  Log["AppendFolder"]("Fonts used for character recognition:");
  for (var i = 0; i < Count; i++)
    Log["Message"](Fonts["Item"](i)["Name"]);
  Log["PopLogFolder"]();

}

See Also

Optical Character Recognition
OCRObject Object
Using Optical Character Recognition - Tips

Highlight search results