OCR.CreateObject Method

Applies to TestComplete 14.40, last modified on April 22, 2021
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 OCR.CreateObject method lets you specify an onscreen object for character recognition.

Declaration

OCR.CreateObject(Object)

Object [in]    Required    OleVariant    
Result An OCRObject object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Object

The onscreen object whose visible text you want to recognize.

Result Value

An OCRObject object used to perform character recognition within the visible area of the specified onscreen object.

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 OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, s, X, Y;
  // Obtain the Notepad window
  notepad = Sys.Process("notepad");
  Window = notepad.Window("Notepad", "*").Window("Edit");

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

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

  // Recognize the text
  s = OCRObj.GetText();

  // Post the recorgnized text to the test log
  Log.Message("See the recognized text in the Details panel.", s);

}

Python

def OCROptionsSample():
  # Obtain the Notepad window
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  # Capture an image of the Notepad window and post it to the test log
  Rect = Window.Picture()
  Log.Picture(Rect, "Region with the text to be recognized")
  # Create an OCR object
  OCRObj = OCR.CreateObject(Rect)
  # Recognize the text
  s = OCRObj.GetText()
  # Post the recorgnized text to the test log
  Log.Message("See the recognized text in the Details panel.", s)

VBScript

Sub OCROptionsSample

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

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

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

  ' Recognize the text
  s = OCRObj.GetText()

  ' Post the recorgnized text to the test log
  Call Log.Message("See the recognized text in the Details panel.", s)

End Sub

DelphiScript

procedure OCROptionsSample();
var notepad, Window, Rect, OCRObj, s, X, Y: OleVariant;
begin
  // Obtain the Notepad window
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');

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

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

  // Recognize the text
  s := OCRObj.GetText();

  // Post the recorgnized text to the test log
  Log.Message('See the recognized text in the Details panel.', s);

end;

C++Script, C#Script

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, s, X, Y;
  // Obtain the Notepad window
  notepad = Sys["Process"]("notepad");
  Window = notepad["Window"]("Notepad", "*")["Window"]("Edit");

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

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

  // Recognize the text
  s = OCRObj["GetText"]();

  // Post the recorgnized text to the test log
  Log["Message"]("See the recognized text in the Details panel.", s);

}

See Also

OCRObject Object

Highlight search results