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 engine can use its own algorithm or classic algorithm for recognition. By default, the engine uses its own algorithm. By assigning True to the GrayScaleBinarization
property, you command the engine to use the classic grayscale algorithm. In some cases, this may improve the recognition results.
The classic grayscale algorithm uses the binarization threshold that is specified by the OCROptions.BinarizationThreshold
property. So, if you assign True to GrayScaleBinarization
, the OCR engine will use the BinarizationThreshold
value for recognition. If GrayScaleBinarization
is False, the default binarization threshold (130) is used. To learn more about grayscale binarization and its usage during character recognition in TestComplete, see Optical Character Recognition.
Declaration
OCROptionsObj.GrayScaleBinarization
Read-Write Property | Boolean |
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
True if the classic grayscale custom threshold is used. False if the default threshold is used.
Example
The following example sets OCR’s grayscale binarization threshold value and uses it to recognize the text within the Web Orders sample application.
Note: | Before running the code snippet below, make sure Google Chrome is installed on your computer. |
JavaScript, JScript
{
var url = "http://support.smartbear.com/Samples/TestComplete12/WebOrders/";
// Launches the browser and opens a web page
Browsers.Item(btChrome).Run(url);
var page = Sys.Browser("chrome").Page("*");
var testObj = page.Form("aspnetForm").Panel(2).TextNode(1);
// Obtain the area with the text to be recognized
// And post it to the test log
var rect = testObj.Picture();
Log.Picture(rect, "Region with the text to be recognized");
// Create an OCR object
OCRObj = OCR.CreateObject(rect);
// Create an OCROptions object
OCROptions = OCRObj.CreateOptions();
// Specify that the character recognition threshold will be set manually
OCROptions.GrayScaleBinarization = true;
// Set the threshold value
OCROptions.BinarizationThreshold = 220;
// Recognize the text
s = OCRObj.GetText(OCROptions);
// Post the recognized text to the test log
Log.Message("The found text is shown in the Additional Info panel.", s);
}
Python
def OCROptionsSample():
url = "http://support.smartbear.com/Samples/TestComplete11/WebOrders/"
# Launches the browser and opens a web page
Browsers.Item[btChrome].Run(url)
page = Sys.Browser("chrome").Page("*")
testObj = page.Form("aspnetForm").Panel(2).TextNode(1)
# Obtain the area with the text to be recognized
# And post it to the test log
rect = testObj.Picture()
Log.Picture(rect, "Region with the text to be recognized")
# Create an OCR object
OCRObj = OCR.CreateObject(rect)
# Create an OCROptions object
OCROptions = OCRObj.CreateOptions()
# Specify that the character recognition threshold will be set manually
OCROptions.GrayScaleBinarization = True
# Set the threshold value
OCROptions.BinarizationThreshold = 220
# Recognize the text
s = OCRObj.GetText(OCROptions)
# Post the recognized text to the test log
Log.Message("The found text is shown in the Additional Info panel.", s)
VBScript
url = "http://support.smartbear.com/Samples/TestComplete12/WebOrders/"
' Launches the browser and opens a web page
Browsers.Item(btChrome).Run url
Set page = Sys.Browser("chrome").Page("*")
Set testObj = page.Form("aspnetForm").Panel(2).TextNode(1)
' Obtain the area with the text to be recognized
' And post it to the test log
Set rect = testObj.Picture
Call Log.Picture(rect, "Region with the text to be recognized")
' Create an OCR object
Set OCRObj = OCR.CreateObject(rect)
' Create an OCROptions object
Set OCROptions = OCRObj.CreateOptions
' Specify that the character recognition threshold will be set manually
OCROptions.GrayScaleBinarization = True
' Set the threshold value
OCROptions.BinarizationThreshold = 220
' Recognize the text
s = OCRObj.GetText(OCROptions)
' Post the recognized text to the test log
Call Log.Message("The found text is shown in the Additional Info panel.", s)
End Sub
DelphiScript
var url, page, testObj, rect, OCRObj, OCROptions, s : OleVariant;
begin
url := 'http://support.smartbear.com/Samples/TestComplete12/WebOrders/';
// Launches the browser and opens a web page
Browsers.Item(btChrome).Run(url);
page := Sys.Browser('chrome').Page('*');
testObj := Page.Form('aspnetForm').Panel(2).TextNode(1);
// Obtain the area with the text to be recognized
// And post it to the test log
rect := testObj.Picture;
Log.Picture(rect, 'Region with the text to be recognized');
// Create an OCR object
OCRObj := OCR.CreateObject(rect);
// Create an OCROptions object
OCROptions := OCRObj.CreateOptions;
// Specify that the character recognition threshold will be set manually
OCROptions.GrayScaleBinarization := true;
// Set the threshold value
OCROptions.BinarizationThreshold := 220;
// Recognize the text
s := OCRObj.GetText(OCROptions);
// Post the recognized text to the test log
Log.Message('The found text is shown in the Additional Info panel.', s);
end;
C++Script, C#Script
{
var url = "http://support.smartbear.com/Samples/TestComplete12/WebOrders/";
// Launches the browser and opens a web page
Browsers["Item"](btChrome)["Run"](url);
var page = Sys["Browser"]("chrome")["Page"]("*");
testObj = page["Form"]("aspnetForm")["Panel"](2)["TextNode"](1);
// Obtain the area with the text to be recognized
// And post it to the test log
rect = testObj["Picture"]();
Log.Picture(rect, "Region with the text to be recognized");
// Create an OCR object
OCRObj = OCR["CreateObject"](rect);
// Create an OCROptions object
OCROptions = OCRObj["CreateOptions"]();
// Specify that the character recognition threshold will be set manually
OCROptions["GrayScaleBinarization"] = true;
// Set the threshold value
OCROptions["BinarizationThreshold"] = 220;
// Recognize the text
s = OCRObj["GetText"](OCROptions);
// Post the recognized text to the test log
Log["Message"]("The found text is shown in the Additional Info panel.", s);
}
See Also
OCROptions.BinarizationThreshold
OCROptions.RecognitionRejectionAuto
Optical Character Recognition
Using Optical Character Recognition - Tips