public class HistogramComparisonModule extends Object implements ImageComparisonModule, ConfigurationKeys, Stoppable, Measurable, Plugin
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
CONTEXT_OBJECT_IMAGE_COMPARISON_FAILURE_DESC, SEARCH_COORD_LIST
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
Constructor and Description |
---|
HistogramComparisonModule() |
Modifier and Type | Method and Description |
---|---|
void |
checkDependencies(PluginManager manager)
Check whether the current product installation contains all dependencies
(other plugins) required to install this plugin.
|
float |
compare(ImageHistogram h,
Image img,
Rectangle rect) |
float |
compare(Image img1,
Rectangle area,
Image img2,
String methodParams,
ScriptingContext repository,
float passRate)
Compare the desktop image to another image and return a number indicating how much they match.
|
float |
compareHistograms(ImageHistogram h1,
ImageHistogram h2) |
float |
compareToBaseImage(Image img2,
Rectangle area,
String methodParams,
ScriptingContext repository,
float passRate)
Compare the desktop image to the base image and return a number indicating how much they match.
|
String |
getCode()
Get plugin code.
|
Date |
getDate()
Get plugin release date.
|
String |
getDescription()
Get plugin description to be displayed in the GUI.
|
String |
getDisplayName()
Get short plugin name to be displayed in the GUI.
|
ImageHistogram |
getHistogram(Image img,
Rectangle rect) |
ImageHistogram |
getHistogram(int[] pixels,
Rectangle histRect,
Rectangle sourceRect) |
Class |
getImplementedInterface()
Get Class of the exposed functional interface that this plugin implements.
|
int[] |
getLowestSupportedVersion()
Get the lowest required version of T-Plan Robot Enterprise.
|
String |
getMessageAfterInstall()
Get text of a message to be displayed after installation of this plugin.
|
String |
getMessageBeforeInstall()
Get text of a message to be displayed before installation of this plugin.
|
String |
getMethodDescription()
Get the method description.
|
String |
getMethodName()
Get the method name.
|
int[] |
getPixels(Image img,
Rectangle r) |
float |
getProgress()
Get the task progress where 0 means "0% done" and 1 means "100% done".
|
String |
getSupportContact()
Get support contact.
|
String |
getUniqueId()
Get unique ID associated with the plugin.
|
String |
getVendorHomePage()
Get the vendor home page.
|
String |
getVendorName()
Get vendor (provider) name to be displayed in the GUI.
|
int[] |
getVersion()
Get plugin version in form of an integer array.
|
boolean |
isMethodParamsSupported()
Define whether this module supports some custom parameters which can be passed via the
methodparams
parameter of the scripting language. |
boolean |
isSecondImageRequired()
Determine whether we are comparing two images or just analyze the desktop image.
|
boolean |
isStopped()
Find out whether the task has been already stopped.
|
boolean |
requiresRestart()
Indicate whether installation of this plugin requires application restart.
|
void |
setBaseImage(Image img)
Set the base image.
|
void |
stop()
Call this method to request the implementing object to stop the current
task or activity.
|
String |
toString() |
public void stop()
Stoppable
public boolean isStopped()
Stoppable
public float getProgress()
Measurable
getProgress
in interface Measurable
public float compare(Image img1, Rectangle area, Image img2, String methodParams, ScriptingContext repository, float passRate)
ImageComparisonModule
compare
in interface ImageComparisonModule
img1
- desktop image.area
- a rectangle area of the remote desktop to be used for image comparison. If the argument is null,
the whole remote desktop image will be used.img2
- another image to be compared to the desktop image.methodParams
- method parameters passed by the 'methodparams'
parameter of
the 'CompareTo'
and 'Waitfor update'
commands. You can use this to pass custom
parameters from the script to this module.repository
- a Map with execution context. Note that most of the objects contain there are not public
and the parameter is specified here to allow compatibility among the custom and internal comparsion methods.passRate
- pass rate in form of a float value between 0 and 1. This user input value indicates
the lowest result which will be considered as match ("passed"). It is in fact the number specified by the
'passrate' parameter of the
commands Screenshot,
Compareto and
Waitfor match/mismatch.public void setBaseImage(Image img)
ImageComparisonModule
This is just a convenience method used by the 'Waitfor match'
command to perform repeated image
comparisons against one image.
The default image comparison algorithm is based on color histograms. When you call this method,
a histogram is calculated for the base image and cached for future repeated comparisons performed through the
compareToBaseImage()
method calls. As calculation of a color histograms is quite a time expensive
operation, this approach allows to achieve higher performance.
See the compareToBaseImage()
method doc for more info.
setBaseImage
in interface ImageComparisonModule
img
- the base (component) image.public float compareToBaseImage(Image img2, Rectangle area, String methodParams, ScriptingContext repository, float passRate)
ImageComparisonModule
This is just a convenience method used by the 'Waitfor match'
command to perform repeated image
comparisons against one image.
The default image comparison algorithm is based on color histograms. A call of this method performs image comparison against precalculated base image histogram rather that against the base image pixels. As calculation of a color histograms is quite a time expensive operation, this approach allows to achieve higher performance.
Any custom implementation of this interface may or may not take advantage of this approach. If you don't want
to diferentiate between repeated and one time comparison calls, define the setBaseImage()
and
compareToBaseImage()
methods as follows:
// Base image private Image baseImage; // Set the base image public void setBaseImage(Image img) { baseImage = img; } // Compare an image with the base image public float compareToBaseImage(Image desktopImage) { return compare(desktopImage, baseImage); }
compareToBaseImage
in interface ImageComparisonModule
img2
- an image to be compared to the base image.area
- a rectangle area of the remote desktop to be used for image comparison. If the argument is null,
the whole remote desktop image will be used.methodParams
- method parameters passed by the 'methodparams'
parameter of
the 'CompareTo'
or 'Waitfor update'
command.repository
- a Map with execution context. Note that most of the objects contain there are not public
and the parameter is specified here to allow compatibility among the custom and internal comparsion methods.passRate
- pass rate in form of a float value between 0 and 1. This user input value indicates
the lowest result which will be considered as match ("passed"). It is in fact the number specified by the
'passrate' parameter of the commands Screenshot,
Compareto and
Waitfor match/mismatch.public boolean isSecondImageRequired()
ImageComparisonModule
If this method returns true, commands CompareTo
and WaitFor update
of the scripting language will require presence of the 'template'
parameter which
specifies an image located in the filesystem to be compared to the current desktop.
If you wish just to analyze the desktop image instead of comparing it to another one, implement this method
to return false. The tool will not validate whether an image from the file system is
passed correctly. Note that commands will supply null instead of an image in all arguments
corresponding to the template image, i.e. expect method calls like compare(desktopImage, null)
and
setBaseImage(null)
.
isSecondImageRequired
in interface ImageComparisonModule
public boolean isMethodParamsSupported()
ImageComparisonModule
methodparams
parameter of the scripting language.
When this method returns false, the tool will report a syntax error when this module gets used in a command
together with the methodparams
parameter.
When this method returns true, commands using this module may take advantage of the methodparams
parameter to pass custom parameters which are not defined by the scripting language.
The default image comparison algorithm doesn't provide any custom parameters.
isMethodParamsSupported
in interface ImageComparisonModule
public String getMethodName()
ImageComparisonModule
module
of the 'CompareTo'
and 'Waitfor update'
commands) and in default comparison method configuration (user config parameter
CompareToCommand.defaultComparisonModule
).
Method names are not case sensitive. Be sure not to specify a name which is reserved by
the tool or already used by another method. Version 1.3 reserves two names, 'default'
and search
. You can't override these names.
getMethodName
in interface ImageComparisonModule
public String getMethodDescription()
ImageComparisonModule
getMethodDescription
in interface ImageComparisonModule
public ImageHistogram getHistogram(Image img, Rectangle rect)
public ImageHistogram getHistogram(int[] pixels, Rectangle histRect, Rectangle sourceRect)
public float compare(ImageHistogram h, Image img, Rectangle rect)
public float compareHistograms(ImageHistogram h1, ImageHistogram h2)
public String getCode()
Plugin
Get plugin code. This string serves as an identifier of the functionality delivered by the plugin. For example, desktop client plugins return protocol name like "RFB" or "RDP" as their code.
Plugin code is used by pluggable instance factories to identify
a particular plugin. It may be used to replace internal plugins with
third party code. For
example if you develop a class which implements this and the
com.tplan.robot.remoteclient.RemoteDesktop
interfaces and the
getCode()
method returns "RFB", it will replace the internal
implementation of the RFB (VNC) client.
public String getDisplayName()
Plugin
getDisplayName
in interface Plugin
public String getDescription()
Plugin
getDescription
in interface Plugin
public String getVendorName()
Plugin
getVendorName
in interface Plugin
public String getSupportContact()
Plugin
getSupportContact
in interface Plugin
public int[] getVersion()
Plugin
new int[] { 1, 2, 3 }
.getVersion
in interface Plugin
public Class getImplementedInterface()
Plugin
com.tplan.robot.remoteclient.RemoteDesktopClient.class
.getImplementedInterface
in interface Plugin
public boolean requiresRestart()
Plugin
requiresRestart
in interface Plugin
public String getVendorHomePage()
Plugin
getVendorHomePage
in interface Plugin
public String getUniqueId()
Plugin
Get unique ID associated with the plugin. The plugin manager uses the ID together with the version string to identify whether a plugin is already installed and whether a newer version of the same plugin is available.
The unique ID in fact identifies a particular plugin delivered by a particular vendor. Plugin developers are recommended to choose an ID and keep it constant for all versions of one particular plugin. The ID is never displayed in the GUI so it doesn't have to be a readable text. To avoid conflicts with other vendors it is recommended to elaborate vendor or author name and feature description into the ID, for example "custom RFB client implemented by John Doe".
getUniqueId
in interface Plugin
public int[] getLowestSupportedVersion()
Plugin
getLowestSupportedVersion
in interface Plugin
public String getMessageBeforeInstall()
Plugin
getMessageBeforeInstall
in interface Plugin
public String getMessageAfterInstall()
Plugin
getMessageAfterInstall
in interface Plugin
public void checkDependencies(PluginManager manager) throws DependencyMissingException
Plugin
DependencyMissingException
if one or more dependencies are missing.checkDependencies
in interface Plugin
manager
- shared instance of the plugin manager.DependencyMissingException
- when one or more dependencies requested by this plugin is missing.