OCRObject Object

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 object is used to perform optical character recognition in the visible area of an onscreen object. To get the OCRObject object, call the OCR.CreateObject method and pass it the needed on-screen object as a parameter.

Members

Example

The following example captures an image of the Windows Notepad window and uses it to create a new OCRObject. After that, it recognizes the characters written in Notepad and posts them to the test log.

JavaScript, JScript

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

  // Captures an image of the Notepad window and posts it to the test log
  Rect = Window.Picture();
  Log.Picture(Rect, "Region with the text to be recognized");

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

  // Recognizes the text and posts it to the test log
  Log.Message("Recognized text:", OCRObj.GetText());

}

Python

def OCRobjectSample():
  # Obtains the Notepad window
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  # Captures an image of the Notepad window and posts it to the test log 
  Rect = Window.Picture()
  Log.Picture(Rect, "Region with the text to be recognized")
  # Creates an OCR object 
  OCRObj = OCR.CreateObject(Rect)
  # Recognizes the text and posts it to the test log 
  Log.Message("Recognized text:", OCRObj.GetText())

VBScript

Sub OCRobjectSample

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

  ' Captures an image of the Notepad window and posts it to the test log
  Set Rect = Window.Picture
  Call Log.Picture(Rect, "Region with the text to be recognized")

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

  ' Recognizes the text and posts it to the test log
  Call Log.Message("Recognized text:", OCRObj.GetText)

End Sub

DelphiScript

procedure OCRobjectSample();
var notepad, Window, Rect, OCRObj : OleVariant;
begin
  // Obtains the Notepad window
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');

  // Captures an image of the Notepad window and posts it to the test log
  Rect := Window.Picture;
  Log.Picture(Rect, 'Region with the text to be recognized');

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

  // Recognizes the text and posts it to the test log
  Log.Message('Recognized text:', OCRObj.GetText);

end;

C++Script, C#Script

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

  // Captures an image of the Notepad window and posts it to the test log
  Rect = Window["Picture"]();
  Log["Picture"](Rect, "Region with the text to be recognized");

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

  // Recognizes the text and posts it to the test log
  Log["Message"]("Recognized text:", OCRObj["GetText"]());

}

See Also

Optical Character Recognition
OCR Object
Using Optical Character Recognition - Tips

Highlight search results