PALATINELABSDocsENES

Pages

↑↓ to moveEnter to openEsc to close

Image recognition package guide

Find pixel templates in saved images and visible Windows windows.

Version 2.17.1. Installed versions can differ. Examples are illustrative and not tested. Packages.

Jump to actions

Prerequisites

Sample files. Make samples/needle.png, a 20 by 20 pixel solid red square. Make samples/haystack.png, a 240 by 200 white image with the same red square at (60, 40). For window examples, show the same pixels in a test window named Invoice Preview. In actions, Action to take on target coordinates is Leftclick by default, so set None when you do not want a click.

Shared fields

Search fields

All commands use these optional fields.

InputEditor fieldType and runtime defaultUse
hasRepeatOptionSetRepeat if image not foundBoolean⁠; falsetrue tries again while the match is not found. false searches once. A found match stops the retries. A missing file or window fails at once, without retries.
repeatTimesTimesNumber⁠; 1The total number of tries, including the first. Used only when Repeat is true⁠. Values below 1 become 1. Each try reads the source file or the window again. The target file is read once.
waitBetweenRepeatsWait between repeats(ms)Number⁠; 500Milliseconds between tries. 0 or less: no wait.
matchPercentageMatch percentageNumber⁠; 100How much of the target must match, from 0 to 100. Values outside that range use the nearest limit. A pixel matches when its red, green and blue are each within the tolerance. 100 needs every pixel. 95 lets up to 5% of the pixels differ.
occurrenceSelected match numberNumber⁠; 1Which match to use when the target shows more than once: 1 is the first, counted top to bottom, then left to right. Values below 1 become 1. Matches on one row do not overlap. A match number that does not exist counts as not found.
toleranceToleranceNumber⁠; 0How much a color can differ, in percent from 0 to 100. Values outside that range use the nearest limit. 0 needs the exact color. The percent applies to each of red, green and blue on a 0 to 255 scale, so 10 allows a difference of up to 26 in each.

Window fields

The commands that search in a window use these optional fields. Area and wait values are whole numbers.

InputEditor fieldType and runtime defaultUse
windowTitleSource window (haystack)String⁠; ""The title of an open window, such as Invoice Preview⁠. A missing window fails. Keep it visible and not covered.
windowTitleMatchMatch the titleWindowMatch⁠; ContainsContains⁠: part of the title. Exact⁠: the whole title. Wildcard⁠: * and ?⁠. Regex⁠: a regular expression. ActiveWindow⁠: the window in front, whatever its title. Plain title comparisons ignore case. If several windows match, the window of the newest program is used.
leftArea left (px from the window)Number⁠; 0Search area: pixels from the window's left edge. 0 starts at the edge.
topArea top (px from the window)Number⁠; 0Search area: pixels from the window's top edge. 0 starts at the edge.
widthArea width (px, 0 = to the window edge)Number⁠; 0Search area width in pixels. 0 or less: up to the window edge. The area is cut to fit the window. An area with nothing left inside the window fails.
heightArea height (px, 0 = to the window edge)Number⁠; 0Search area height in pixels. 0 or less: up to the window edge. The same rules as width.
waitBeforeCaptureWait in ms before capturing windowNumber⁠; 0Milliseconds to wait before the first capture. 0 or less: no wait. It does not wait for a missing window to open.

Target point fields

The commands that search in a window use these optional fields for the point they return or click. Offsets are whole pixels.

InputEditor fieldType and runtime defaultUse
selectClickOrOffsetMatchTarget coordinate selectionsClickTarget⁠; ClickMatchClickMatch⁠: the center of the match. OffsetMatch⁠: the top-left corner of the match plus offsetX and offsetY⁠. Coordinates are screen pixels.
offsetXHorizontal offsetNumber⁠; 0For OffsetMatch only: pixels to the right. A negative value goes left.
offsetYVertical offsetNumber⁠; 0For OffsetMatch only: pixels down. A negative value goes up.

Actions

Find image in window (imageRecognitionFindFileImageInWindowImage)

Find a saved image in a visible window, return its screen point, and click it if you choose. If no match is found, the step fails.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
actionTypeAction to take on target coordinatesClickAction⁠; LeftclickOptional. Leftclick⁠, Doubleclick or Rightclick moves the pointer to the point and clicks. None only returns the point. Choices: Leftclick⁠, Doubleclick⁠, Rightclick⁠, None⁠.

Also uses the search fields, window fields and target point fields.

Outputs

OutputTypeMeaning and binding
xNumberThe screen X of the point: the center of the match, or its top-left corner plus the offsets. Save it in a Number variable.
yNumberThe screen Y of the point, in the same way. Save it in a Number variable.

Example

Show the red square at screen position (160, 140) inside Invoice Preview. Set Target image (needle)=samples/needle.png, Source window (haystack)=Invoice Preview, Match the title=Exact and Action to take on target coordinates=None. Keep the other fields at their defaults. Save x and y in the Number variables matchX and matchY.

Expected result

x is 170 and y is 150, the center of the 20 by 20 square. With None, the pointer does not move. OffsetMatch with offsets (2, 3) would give (162, 143). If no match is found after all tries, or a file or window is missing, the step fails.

Back to actions

Find window in window (imageRecognitionFindWindowImageInWindowImage)

Find a saved window capture in a visible window. It works the same as Find image in window.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
actionTypeAction to take on target coordinatesClickAction⁠; LeftclickOptional. Leftclick⁠, Doubleclick or Rightclick moves the pointer to the point and clicks. None only returns the point. Choices: Leftclick⁠, Doubleclick⁠, Rightclick⁠, None⁠.

Also uses the search fields, window fields and target point fields.

Outputs

OutputTypeMeaning and binding
xNumberThe screen X of the point: the center of the match, or its top-left corner plus the offsets. Save it in a Number variable.
yNumberThe screen Y of the point, in the same way. Save it in a Number variable.

Example

Show the red square at screen position (160, 140) inside Invoice Preview. Set Target image (needle)=samples/needle.png, Source window (haystack)=Invoice Preview, Match the title=Exact and Action to take on target coordinates=None. Keep the other fields at their defaults. Save x and y in the Number variables matchX and matchY.

Expected result

x is 170 and y is 150, the center of the 20 by 20 square. With None, the pointer does not move. OffsetMatch with offsets (2, 3) would give (162, 143). If no match is found after all tries, or a file or window is missing, the step fails.

Back to actions

Conditions

Image file is found in image file (imageRecognitionFileImageExistInFileImage)

true when a saved image is found in an image file.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageSelect target image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
sourceImageSelect source image (haystack)String⁠; ""Required. The image file to search in, such as samples/haystack.png⁠.

Also uses the search fields.

Outputs

None. The condition is true or false.

Example

Set Target image=samples/needle.png and Select source image (haystack)=samples/haystack.png. Keep the other fields at their defaults.

Expected result

true, because the sample has the red square. Without it, or with a target larger than the source, the condition is false.

Back to conditions

Image file is found in window (imageRecognitionFileImageExistInWindowImage)

true when a saved image is found in a visible window.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageSelect target image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
hasClickOptionIf image is found, click on itBoolean⁠; falseOptional. true left-clicks the point when the target is found, also in a "not found" condition, which is then false⁠. false does not move the pointer.

Also uses the search fields, window fields and target point fields.

Outputs

None. The condition is true or false.

Example

Show the red square in Invoice Preview. Set Target image=samples/needle.png, Source window (haystack)=Invoice Preview and Match the title=Exact. Keep the other fields at their defaults.

Expected result

true, because the sample has the red square. Without it, or with a target larger than the source, the condition is false. The pointer does not move.

Back to conditions

Image file is not found in image file (imageRecognitionFileImageNotExistInFileImage)

true when a saved image is not found in an image file.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageSelect target image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
sourceImageSelect source image (haystack)String⁠; ""Required. The image file to search in, such as samples/haystack.png⁠.

Also uses the search fields.

Outputs

None. The condition is true or false.

Example

Set Target image=samples/needle.png and Select source image (haystack)=samples/haystack.png. Keep the other fields at their defaults.

Expected result

false, because the sample has the red square. Without it, or with a target larger than the source, the condition is true.

Back to conditions

Image file is not found in window (imageRecognitionFileImageNotExistInWindowImage)

true when a saved image is not found in a visible window.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageSelect target image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
hasClickOptionIf image is found, click on itBoolean⁠; falseOptional. true left-clicks the point when the target is found, also in a "not found" condition, which is then false⁠. false does not move the pointer.

Also uses the search fields, window fields and target point fields.

Outputs

None. The condition is true or false.

Example

Show the red square in Invoice Preview. Set Target image=samples/needle.png, Source window (haystack)=Invoice Preview and Match the title=Exact. Keep the other fields at their defaults.

Expected result

false, because the sample has the red square. Without it, or with a target larger than the source, the condition is true. The pointer does not move.

Back to conditions

Window is found in image file (imageRecognitionWindowImageExistInFileImage)

true when a saved window capture is found in an image file.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
sourceImageSelect source image (haystack)String⁠; ""Required. The image file to search in, such as samples/haystack.png⁠.

Also uses the search fields.

Outputs

None. The condition is true or false.

Example

Set Target image=samples/needle.png and Select source image (haystack)=samples/haystack.png. Keep the other fields at their defaults.

Expected result

true, because the sample has the red square. Without it, or with a target larger than the source, the condition is false.

Back to conditions

Window is found in window (imageRecognitionWindowImageExistInWindowImage)

true when a saved window capture is found in a visible window.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
hasClickOptionIf image is found, click on itBoolean⁠; falseOptional. true left-clicks the point when the target is found, also in a "not found" condition, which is then false⁠. false does not move the pointer.

Also uses the search fields, window fields and target point fields.

Outputs

None. The condition is true or false.

Example

Show the red square in Invoice Preview. Set Target image=samples/needle.png, Source window (haystack)=Invoice Preview and Match the title=Exact. Keep the other fields at their defaults.

Expected result

true, because the sample has the red square. Without it, or with a target larger than the source, the condition is false. The pointer does not move.

Back to conditions

Window is not found in image file (imageRecognitionWindowImageNotExistInFileImage)

true when a saved window capture is not found in an image file.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
sourceImageSelect source image (haystack)String⁠; ""Required. The image file to search in, such as samples/haystack.png⁠.

Also uses the search fields.

Outputs

None. The condition is true or false.

Example

Set Target image=samples/needle.png and Select source image (haystack)=samples/haystack.png. Keep the other fields at their defaults.

Expected result

false, because the sample has the red square. Without it, or with a target larger than the source, the condition is true.

Back to conditions

Window is not found in window (imageRecognitionWindowImageNotExistInWindowImage)

true when a saved window capture is not found in a visible window.

Inputs

InputEditor fieldType and runtime defaultUse
targetImageTarget image (needle)String⁠; ""Required. A saved image file, such as samples/needle.png⁠.
hasClickOptionIf image is found, click on itBoolean⁠; falseOptional. true left-clicks the point when the target is found, also in a "not found" condition, which is then false⁠. false does not move the pointer.

Also uses the search fields, window fields and target point fields.

Outputs

None. The condition is true or false.

Example

Show the red square in Invoice Preview. Set Target image=samples/needle.png, Source window (haystack)=Invoice Preview and Match the title=Exact. Keep the other fields at their defaults.

Expected result

false, because the sample has the red square. Without it, or with a target larger than the source, the condition is true. The pointer does not move.

Back to conditions