BinarizationThreshold Property

Applies to TestComplete 15.63, last modified on April 23, 2024
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 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 = "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/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 Details panel.", s)

VBScript

Sub OCROptionsSample

  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

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

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

Highlight search results