CreateOptions Method

Applies to TestComplete 15.68, last modified on October 16, 2024
This method 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 OCRObject.CreateOptions method lets you get an OCROptions object used to configure character recognition settings for an onscreen object.

Declaration

OCRObjectObj.CreateOptions()

OCRObjectObj An expression, variable or parameter that specifies a reference to an OCRObject object
Result An OCROptions object

Applies To

The method is applied to the following object:

Result Value

An OCROptions object.

Remarks

To obtain the OCROptions object that holds the default recognition settings, use the OCRObject.DefaultOptions property.

Example

The following code snippet captures an image of an on-screen object and creates an OCRObject object. After that, it creates an OCROptions object that contains OCR settings, modifies the settings and uses them to recognize the text. The recognized text is posted to the test log.

JavaScript, JScript

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions;
  // Obtains an on-screen object and captures an image of it
  notepad = Sys.Process("notepad");
  Window = notepad.Window("Notepad", "*").Window("Edit");
  Rect = Window.Picture();
  Log.Picture(Rect, "Region with the text to be recognized");

  // Creates an OCR object
  OCRObj = OCR.CreateObject(Rect);
  // Creates an OCROptions object
  OCROptions = OCRObj.CreateOptions();

  // Modifies the OCR options
  OCROptions.ActiveRecognitionSet = 4;
  OCROptions.ExactSearch = false;
  OCROptions.SearchAccuracy = 0.4;

  // Recognizes the text using the specified settings
  // Posts the recognized text to the test log
  Log.Message("Found text:", OCRObj.GetText(OCROptions));

}

Python

def OCROptionsSample():
  # Obtains an on-screen object and captures an image of it
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  Rect = Window.Picture()
  Log.Picture(Rect, "Region with the text to be recognized")
  # Creates an OCR object
  OCRObj = OCR.CreateObject(Rect)
  # Creates an OCROptions object
  OCROptions = OCRObj.CreateOptions()
  # Modifies the OCR options
  OCROptions.ActiveRecognitionSet = 4
  OCROptions.ExactSearch = False
  OCROptions.SearchAccuracy = 0.4
  # Recognizes the text using the specified settings
  # Posts the recognized text to the test log
  Log.Message("Found text:", OCRObj.GetText(OCROptions))

VBScript

Sub OCROptionsSample

  ' Obtains an on-screen object and captures an image of it
  Set notepad = Sys.Process("notepad")
  Set Window = notepad.Window("Notepad", "*").Window("Edit")
  Set Rect = Window.Picture
  Call Log.Picture(Rect, "Region with the text to be recognized")

  ' Creates an OCR object
  Set OCRObj = OCR.CreateObject(Rect)
  ' Creates an OCROptions object
  Set OCROptions = OCRObj.CreateOptions

  ' Modifies the OCR options
  OCROptions.ActiveRecognitionSet = 4
  OCROptions.ExactSearch = False
  OCROptions.SearchAccuracy = 0.4

  ' Recognizes the text using the specified settings
  ' Posts the recognized text to the test log
  Call Log.Message("Found text:", OCRObj.GetText(OCROptions))

End Sub

DelphiScript

procedure OCROptionsSample();
var notepad, Window, Rect, OCRObj, OCROptions;
begin
  // Obtains an on-screen object and captures an image of it
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');
  Rect := Window.Picture;
  Log.Picture(Rect, 'Region with the text to be recognized');

  // Creates an OCR object
  OCRObj := OCR.CreateObject(Rect);
  // Creates an OCROptions object
  OCROptions := OCRObj.CreateOptions();

  // Modifies the OCR options
  OCROptions.ActiveRecognitionSet := 4;
  OCROptions.ExactSearch := false;
  OCROptions.SearchAccuracy := 0.4;

  // Recognizes the text using the specified settings
  // Posts the recognized text to the test log
  Log.Message('Found text:', OCRObj.GetText(OCROptions));

end;

C++Script, C#Script

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions;
  // Obtains an on-screen object and captures an image of it
  notepad = Sys["Process"]("notepad");
  Window = notepad["Window"]("Notepad", "*")["Window"]("Edit");
  Rect = Window["Picture"]();
  Log["Picture"](Rect, "Region with the text to be recognized");

  // Creates an OCR object
  OCRObj = OCR["CreateObject"](Rect);
  // Creates an OCROptions object
  OCROptions = OCRObj["CreateOptions"]();

  // Modifies the OCR options
  OCROptions["ActiveRecognitionSet"] = 4;
  OCROptions["ExactSearch"] = false;
  OCROptions["SearchAccuracy"] = 0.4;

  // Recognizes the text using the specified settings
  // Posts the recognized text to the test log
  Log["Message"]("Found text:", OCRObj["GetText(OCROptions)"]);

}

See Also

DefaultOptions Property
OCROptions Object
Using Optical Character Recognition - Tips

Highlight search results