BinarizationThreshold Property

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 OCROptions.BinarizationThreshold property lets you specify the threshold used to decide whether the given pixel of a grayscale image is black or white. To learn more about grayscale binarization and its usage during character recognition in TestComplete, see Optical Character Recognition. The value set in this property takes effect only if the OCROptions.GrayScaleBinarization property is True.

Declaration

OCROptionsObj.BinarizationThreshold

Read-Write Property Integer
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

An integer value that denotes the binarization threshold. The property value can range between 0 and 255. The default value, which is used when OCROptions.GrayScaleBinarization is False, is 130.

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

function OCROptionsSample()
{
  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

Sub OCROptionsSample

  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

procedure OCROptionsSample();
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

function OCROptionsSample()
{
  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.GrayScaleBinarization
Optical Character Recognition
Using Optical Character Recognition - Tips

Highlight search results