SearchAccuracy Property

Applies to TestComplete 15.62, last modified on March 19, 2024
This property 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.SearchAccuracy property defines a numerical representation of how much the recognized string should match the string passed to the OCRObject.FindRectByText method in order to consider them as identical. This property is used only when the OCROptions.ExactSearch property is set to False.

To learn more about character recognition in TestComplete, see Using Optical Character Recognition.

Declaration

OCROptionsObj.SearchAccuracy

Read-Write Property Double
OCROptionsObj An expression, variable or parameter that specifies a reference to an OCROptions object

Applies To

The property is applied to the following object:

Property Value

A real value ranging from 0 to 1 that denotes the accuracy of string comparison. If SearchAccuracy is set to 1, the exact string matches will be sought. The default value of this property is 0.6.

Example

The following example uses the OCROptions object to specify that the OCRobject.FindRectByText method will not use the exact search and sets the search accuracy to 0.3. After that, it searches for the "Test" string within the text written in Windows Notepad by using the specified OCR options. The rectangle containing the found text is posted to the test log.

JavaScript, JScript

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions, RectResult;
  // Obtains the Notepad window
  notepad = Sys.Process("notepad");
  Window = notepad.Window("Notepad", "*").Window("Edit");

  // Captures an image of the Notepad window
  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();

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = false;

  // Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3;

  // Searches for the rectangle that contains the "Test" string
  var FindResult = OCRObj.FindRectByText("Test", OCROptions);
  if (FindResult)
  {
    // Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft;
    Y = OCRObj.FoundTop;
    dX = OCRObj.FoundWidth;
    dY = OCRObj.FoundHeight;

    RectResult = Window.Picture(X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log.Picture(RectResult, "Region with the found text:");
  }
}

Python

def OCROptionsSample():
  # Obtains the Notepad window
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  # Captures an image of the Notepad window
  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()
  # Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = False
  # Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3
  # Searches for the rectangle that contains the "Test" string
  FindResult = OCRObj.FindRectByText("Test", OCROptions)
  if FindResult:
    # Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft
    Y = OCRObj.FoundTop
    dX = OCRObj.FoundWidth
    dY = OCRObj.FoundHeight
    RectResult = Window.Picture(X, Y, dX, dY)
    # Posts the found rectangle to the test log
    Log.Picture(RectResult, "Region with the found text:")

VBScript

Sub OCROptionsSample

  ' Obtains the Notepad window
  Set notepad = Sys.Process("notepad")
  Set Window = notepad.Window("Notepad", "*").Window("Edit")

  ' Captures an image of the Notepad window
  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

  ' Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = False

  ' Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3

  ' Searches for the rectangle that contains the "Test" string
  FindResult = OCRObj.FindRectByText("Test", OCROptions)
  If FindResult Then
    ' Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft
    Y = OCRObj.FoundTop
    dX = OCRObj.FoundWidth
    dY = OCRObj.FoundHeight

    Set RectResult = Window.Picture(X, Y, dX, dY)
    ' Posts the found rectangle to the test log
    Call Log.Picture(RectResult, "Region with the found text:")
  End If

End Sub

DelphiScript

procedure OCROptionsSample();
var
  notepad, Window, Rect, OCRObj, OCROptions, RectResult : OleVariant;
  FindResult : boolean;
  X, Y, dX, dY : integer;
begin
  // Obtains the Notepad window
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');

  // Captures an image of the Notepad window
  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;

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch := false;

  // Specifies the comparison accuracy
  OCROptions.SearchAccuracy := 0.3;

  // Searches for the rectangle that contains the "Test" string
  FindResult := OCRObj.FindRectByText('Test', OCROptions);
  if FindResult then
  begin
    // Obtains the coordinates and the size of the found rectangle
    X := OCRObj.FoundLeft;
    Y := OCRObj.FoundTop;
    dX := OCRObj.FoundWidth;
    dY := OCRObj.FoundHeight;

    RectResult := Window.Picture(X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log.Picture(RectResult, 'Region with the found text:');
  end;
end;

C++Script, C#Script

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions, RectResult;
  // Obtains the Notepad window
  notepad = Sys["Process"]("notepad")
  Window = notepad["Window"]("Notepad", "*")["Window"]("Edit");

  // Captures an image of the Notepad window
  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"]();

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions["ExactSearch"] = false;

  // Specifies the comparison accuracy
  OCROptions["SearchAccuracy"] = 0.3;

  // Searches for the rectangle that contains the "Test" string
  var FindResult = OCRObj["FindRectByText"]("Test", OCROptions);
  if (FindResult)
  {
    // Obtains the coordinates and the size of the found rectangle
    X = OCRObj["FoundLeft"];
    Y = OCRObj["FoundTop"];
    dX = OCRObj["FoundWidth"];
    dY = OCRObj["FoundHeight"];

    RectResult = Window["Picture"](X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log["Picture"](RectResult, "Region with the found text:");
  }
}

See Also

ExactSearch Property
FindRectByText Method
Using Optical Character Recognition
Using Optical Character Recognition - Tips

Highlight search results