public class ImageComparisonModuleFactory extends PluginFactory implements ConfigurationKeys
Image comparison module factory allows to access image comparison
algorithms provided by this application. As the factory is built on top of
the plugin framework, it is possible to plug in additional modules to the
application through the Plugin
interface.
An image comparison module is a Java class or set of classes implementing
the ImageComparisonModule
.
The module allows to compare two images or eventually analyze one single base image.
The first image argument is typically called base image. The second
image is often called template image or pattern image.
To get an instance of image comparison module factory use static method
getInstance()
. Then take advantage of the getModule(java.lang.String)
method
to obtan a module by its name.
T-Plan Robot Enterprise provides by default two image comparison modules named "default" (constant MODULE_DEFAULT
)
and "search" (constant MODULE_SEARCH
). The following paragraphs provide just a general
description. See the Image Comparison With T-Plan Robot Enterprise document for details on the built-in comparison
algorithms.
Image Comparison Module "default"
The default module is based on comparison of color histograms. It returns
a float number between 0 and 1 representing a ratio of how much two images
match in terms of having the same amounts of
pixels of each color. This module is typically used in T-Plan Robot Enterprise to verify
larger remote screen changes, e.g. making sure that an application window
displayed on the screen correctly or that a web browser running on the remote
desktop displayed a correct static web page.
Image Comparison Module "search"
The search module performs pixel by pixel search of a smaller image
pattern, typically an icon or image of a component. It is either possible to
search for an exact 100% match or specify a pass rate between 0 and 1 which
defines ratio of allowed different pixels.
The search module is able to handle template images with transparency. As transparent pixels are not compared and they are always counted as matching, it allows users to add transparency to their template images to implement more robust search of patterns in changing environments, e.g. where a background color change is expected.
The search module returns either 1 when at least one match is found or
0 (zero) otherwise. List of match coordinates (Point
instances) is stored to the repository
argument table with key
defined by the ImageComparisonModule.SEARCH_COORD_LIST
constant.
Example
The following example illustrates a typical usage of the image comparison
API:
import com.tplan.robot.imagecomparison.ImageComparisonModule; import com.tplan.robot.imagecomparison.ImageComparisonModuleFactory; import com.tplan.robot.scripting.ScriptingContext; import com.tplan.robot.scripting.ScriptingContextImpl; import java.io.File; import java.io.IOException; import java.util.List; import javax.imageio.ImageIO; import java.awt.Point; public class ImageComparisonExample { public static void main(String[] args) throws IOException { ImageComparisonModuleFactory factory = ImageComparisonModuleFactory.getInstance(); ScriptingContext context = new ScriptingContextImpl(); // -------------------------------------------------------------------- // EXAMPLE #1: Image comparison using the "default" module. // We will compare two images called "desktop1.png" and "desktop2.png". // -------------------------------------------------------------------- ImageComparisonModule module1 = factory.getModule("default"); float comparisonResult1 = module1.compare( ImageIO.read(new File("desktop1.png")), // Remote desktop image (base image) null, // Rectangle of the remote desktop image to search ImageIO.read(new File("desktop2.png")), // Pattern image (template image) null, // Method params (null if no custom params are needed) context, // Context map for storing of test results and statistics 1.0f // Required pass rate (1.0f == 100%); not used in "default" module ); System.out.println("Image comparison using default histogram method finished; result == "+comparisonResult1); // -------------------------------------------------------------------- // EXAMPLE #2: Image comparison using the "search" module. // We will look for image "icon.png" in base image called "desktop1.png". // -------------------------------------------------------------------- ImageComparisonModule module2 = factory.getModule("search"); float comparisonResult2 = module2.compare( ImageIO.read(new File("desktop1.png")), // Remote desktop image (base image) null, // Rectangle of the remote desktop image to search ImageIO.read(new File("icon.png")), // Pattern image (template image) null, // Method params (null if no custom params are needed) context, // Context map for storing of test results and statistics 1.0f // Required image comparison pass rate; 1.0f == 100% ); System.out.println("Image search finished; result == "+comparisonResult2); // Coordinates of image search are saved as a map of numbers List<Point> coords = context.getSearchHits(); // Iterate through the list of coordinates and print them out if (coords != null) { int i = 1; for (Point p : coords) { System.out.println("Match #"+(i++)+": ["+p.x+","+p.y+"]"); } } } }
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static String |
MODULE_DEFAULT
Name of the built-in "default" image comparison module.
|
static String |
MODULE_SEARCH
Name of the built-in "search" image comparison module.
|
CAPTURE_USE_LEGACY_DIALOG, COMPARETO_MAX_LOADED_PIXEL_ROWS, COMPARETO_MAX_SEARCH_HITS, DEFAULT_MODULE_PARAM_NAME, EDITOR_BREAKPOINT_COLOR, EDITOR_EXECUTED_LINE_COLOR, EDITOR_SYNTAX_ERROR_COLOR, IO_ACTIVE_FILE, IO_OPEN_FILE_LIST, IO_RECENT_SCRIPTS, IO_RECENT_SERVERS, MAX_DYNAMIC_MENU_ITEMS, MODULE_LIST_PARAM_NAME, REFRESH_DAEMON_ENABLE, REFRESH_DAEMON_MAX_IDLE_TIME, REPEAT_COMPARISON_FOR_MOVED_MOUSE, SCRIPT_HANDLER_CHECK_SYNTAX_BEFORE_EXECUTION, SCRIPT_HANDLER_OPEN_INCLUDED_FILES, STATUS_BAR_MINIMUM_DISPLAYED_UPDATE_SIZE, TOOLBAR_LOCATION
Modifier and Type | Method and Description |
---|---|
List<String> |
getAvailableModules()
Get a list of available image comparison module names.
|
ImageComparisonModule |
getDefaultModule()
Get the default image comparison module, typically the one called "default".
|
static ImageComparisonModuleFactory |
getInstance()
Get shared instance of this factory.
|
ImageComparisonModule |
getModule(String moduleName)
Get a module by name.
|
public static final String MODULE_DEFAULT
public static final String MODULE_SEARCH
public static ImageComparisonModuleFactory getInstance()
public ImageComparisonModule getDefaultModule()
getModule("default")
.public ImageComparisonModule getModule(String moduleName)
ImageComparisonModule
interface and plugged into the application.moduleName
- module name.