CreateOptions Method

Applies to TestComplete 12.60, last modified on September 17, 2018
The Optical Character Recognition feature provided by the OCR plugin is deprecated. It was removed from TestComplete in version 12.60 and is no longer available for later versions.
Instead, TestComplete version 12.60 introduces the new Optical Character Recognition engine featuring Google Cloud Vision API. To learn more, see Optical Character Recognition.
If you need to use the legacy feature, please contact our Customer Care team.

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