getOcrText

String getOcrText([parameterMap], [searchRegion])

This function will perform optical character recognition on the display also showing the currently running application and return all text lines.

The OCR will be performed over all available screens making up the desktop. At least on Windows and X11-based systems. For OCR on multi-screen setup on macOS please inquire with technical support.

The search behavior can be configured through entries passed via the optional parameterMap argument.

  • language - The language hint for OCR engine. Use an empty string to use the OCR engine defaults. The default value is the value of testSettings.defaultOcrLanguage property.
  • profiles - An array of OCR engine specific profile names. This parameter is used only with engines that support profiles.
  • options - A map of engine-specific option names and values. These options are passed to the OCR engine after loading the specified profiles.
  • scaleFactor - Image up-scale factor. The source image is upscaled by that factor before it is passed to the OCR engine. The default value is 3.5. It can be set to a lower value to improve the OCR performance in case the text is rendered with a large font.
# Get all text using German language hint
test.log( getOcrText( { "language": "German" } ) )
// Get all text using German language hint
test.log( getOcrText( { language: "German" } ) )
# Get all text using German language hint
test::log( getOcrText( { language => "German" } ) )
# Get all text using German language hint
Test.log( getOcrText( { "language" => "German" } ) )
# Get all text using German language hint
test log [ getOcrText { language "German" } ]

In case a searchRegion is specified as the last argument, the OCR is performed only within the area corresponding to it. The search region can be an AUT object, a ScreenRectangle object or an array of such objects. It can also be a special string value "all", in which case all top-level objects are used.

The searchRegion can also be an Image Object object. In such case no new screenshots are taken and the specified image is used instead. Currently it is not possible to limit the OCR scope to a portion of an Image object; please use the Image.copy() to cut the relevant section.

# Find all text on the MyWidget object
test.log( getOcrText( {}, waitForObject( names.MyWidget ) )

# Find all text on multiple objects
test.log( getOcrText( {}, [ waitForObject( names.MyWidget ),
                            waitForObject( names.MyOtherWidget ) ] ) )

# Find all text on the left half of the MyWidget object
bounds = object.globalBounds( waitForObject( names.MyWidget ) )
bounds.width = bounds.width / 2
test.log( getOcrText( {}, bounds ) )

# Find all text in the specified area
test.log( getOcrText( {}, UiTypes.ScreenRectangle( 100, 100, 200, 300 ) ) )

# Find all text on all top-level objects
test.log( getOcrText( {}, "all" ) )
# Find all text on the MyWidget object
test.log( getOcrText( {}, waitForObject( names.MyWidget ) ) );

// Find all text on multiple objects
test.log( getOcrText( {}, [ waitForObject( names.MyWidget ),
                            waitForObject( names.MyOtherWidget ) ] ) );

// Find all text on the left half of the MyWidget object
var bounds = object.globalBounds( waitForObject( names.MyWidget ) );
bounds.width = bounds.width / 2
test.log( getOcrText( {}, bounds ) );

// Find all text in the specified area
test.log( getOcrText( {}, new UiTypes.ScreenRectangle( 100, 100, 200, 300 ) ) );

// Find all text on all top-level objects
test.log( getOcrText( {}, "all" ) );
# Find all text on the MyWidget object
test::log( getOcrText( {}, waitForObject( names::MyWidget ) ) );

# Find all text on multiple objects
test::log( getOcrText( {}, ( waitForObject( names::MyWidget ),
                            waitForObject( names::MyOtherWidget ) ) ) );

# Find all text on the left half of the MyWidget object
my $bounds = object::globalBounds( waitForObject( names::MyWidget ) );
$bounds->width = $bounds->width / 2;
test::log( getOcrText( {}, bounds ) );

# Find all text in the specified area
test::log( getOcrText( {}, new UiTypes::ScreenRectangle( 100, 100, 200, 300 ) ) );

# Find all text on all top-level objects
test::log( getOcrText( {}, "all" ) )
# Find all text on the MyWidget object
Test.log( getOcrText( {}, waitForObject( names.MyWidget ) ) );

# Find all text on multiple objects
Test.log( getOcrText( {}, [ waitForObject( names.MyWidget ),
                            waitForObject( names.MyOtherWidget ) ] ) );

# Find all text on the left half of the MyWidget object
bounds = Squish::Object.globalBounds( waitForObject( names.MyWidget ) );
bounds.width = bounds.width / 2
Test.log( getOcrText( {}, bounds ) );

# Find all text in the specified area
Test.log( getOcrText( {}, UiTypes::ScreenRectangle.new( 100, 100, 200, 300 ) ) );

# Find all text on all top-level objects
Test.log( getOcrText( {}, "all" ) );
# Find all text on the MyWidget object
test log [ getOcrText {} [ waitForObject $names::MyWidget ] ]

# Find all text on multiple objects
test log [ getOcrText {} { [ waitForObject $names::MyWidget ],
                           [ waitForObject $names::MyOtherWidget ] } ]

# Find all text on the left half of the MyWidget object
set bounds [object globalBounds [ waitForObject $names::MyWidget ] ]
property set $bounds width [ expr [ property get $bounds width ] / 2 ]
test log [ getOcrText {} $bounds ]

# Find all text in the specified area
test log [ getOcrText {} [ construct ScreenRectangle 100 100 200 300 ] ]

# Find all text on all top-level objects
test log [ getOcrText {} "all" ]

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Search Results