Pattern

class Pattern

A pattern is used, to associate an image file with additional attributes used in find operations and when acting on a match object.

Minimum Similarity:

While using a Region.find() operation, if only an image file is provided, Sikuli searches the region using a default minimum similarity of 0.7. This default value can be changed in Settings.MinSimilarity.

Using similar() you can associate a specific similarity value, that will be used as the minimum value, when this pattern object is searched. The IDE supports adjusting the minimum similarity of captured images using the Preview Pane (internally in the script, the images are turned into a pattern object automatically).

Click Point:

Normally when clicking on a match, the center pixel of the associated rectangle is used. With a pattern object, you can define a different click point relative to the center using targetOffset().

class Pattern
Pattern(string)
Parameters:string – a path to an image file
Returns:a new pattern object

This will initialize a new pattern object without any additional attributes. As long as no pattern methods are used additionally, it is the same as just using the image file name itself in the find operation.

similar(similarity)

Return a new Pattern object containing the same attributes (image, click point) with the minimum similarity set to the specified value.

Parameters:similarity – the minimum similarity to use in a find operation. The value should be between 0 and 1.
Returns:a new pattern object
exact()

Return a new Pattern object containing the same attributes (image, click point) with the minimum similarity set to 1.0, which means exact match is required.

Returns:a new pattern object
targetOffset(dx, dy)

Return a new Pattern object containing the same attributes (image, similarity), but a different definition for the click. By default, the click point is the center of the found match. By setting the target offset, it is possible to specify a click point other than the center. dx and dy will be used to calculate the position relative to the center.

Parameters:
  • dx – x offset from the center
  • dy – y offset from the center
Returns:

a new pattern object

getFilename()

Get the filename of the image contained in the Pattern object.

Returns:a filename as a string
getTargetOffset()

Get the target offset of the Pattern object.

Returns:a Location object as the target offset