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 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 = "https://services.smartbear.com/Samples/TestComplete15/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 Details panel.", s);
}
Python
def OCROptionsSample():
url = "http://services.smartbear.com/Samples/TestComplete14/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 Details panel.", s)
VBScript
url = "https://services.smartbear.com/Samples/TestComplete15/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 Details panel.", s)
End Sub
DelphiScript
var url, page, testObj, rect, OCRObj, OCROptions, s : OleVariant;
begin
url := 'https://services.smartbear.com/Samples/TestComplete15/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 Details panel.', s);
end;
C++Script, C#Script
{
var url = "https://services.smartbear.com/Samples/TestComplete15/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 Details panel.", s);
}
See Also
OCROptions.BinarizationThreshold
OCROptions.RecognitionRejectionAuto
Optical Character Recognition
Using Optical Character Recognition - Tips