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 OCR
object provides a program interface to optical character recognition in your scripts. This is a top-level object that is available if the OCR plugin (<TestComplete>\Bin\Extensions\tcOCR.pls) is installed.
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 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 Additional Info panel.", s);
}
{
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 Additional Info 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 Additional Info 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 Additional Info panel.", s)
End Sub
' 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 Additional Info 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 Additional Info panel.', s);
end;
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 Additional Info 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 Additional Info panel.", s);
}
{
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 Additional Info panel.", s);
}
See Also
Optical Character Recognition
Using Optical Character Recognition - Tips