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.
Prerequisites
- This package looks for an exact picture, pixel by pixel, on Windows. It does not find a picture that is bigger, smaller or turned, and it does not compare transparency. Save the target at the same size it shows in the source. A target larger than the source is not found.
- Start with Match percentage
100, Tolerance0and a small search area. Low match percentages are slow and can match the wrong place. - A window search needs an open, visible window on a desktop that is signed in, unlocked and connected. It reads the pixels on the screen, so a window on top can change the result. The search area is set once and used again for each retry, so keep the window in place. A click needs a desktop that accepts input.
- In the commands that name "Window" as the thing to find, the target is still a saved image file, not a second live window. Save it first with the Screen package.
- Conditions give only
trueorfalse, with no output variables. A missing or bad image file, a missing window or a search area outside the window stops the step with an error. No file is changed. - Relative file paths start in the Run's working folder. Image files can be PNG, BMP, JPG, GIF or TIFF.
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.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
has | Repeat if image not found | Boolean; false | true 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. |
repeat | Times | Number; 1 | The 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. |
wait | Wait between repeats(ms) | Number; 500 | Milliseconds between tries. 0 or less: no wait. |
match | Match percentage | Number; 100 | How 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. |
occurrence | Selected match number | Number; 1 | Which 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. |
tolerance | Tolerance | Number; 0 | How 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.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
window | Source window (haystack) | String; "" | The title of an open window, such as Invoice Preview. A missing window fails. Keep it visible and not covered. |
window | Match the title | Window; Contains | Contains: part of the title. Exact: the whole title. Wildcard: * and ?. Regex: a regular expression. Active: the window in front, whatever its title. Plain title comparisons ignore case. If several windows match, the window of the newest program is used. |
left | Area left (px from the window) | Number; 0 | Search area: pixels from the window's left edge. 0 starts at the edge. |
top | Area top (px from the window) | Number; 0 | Search area: pixels from the window's top edge. 0 starts at the edge. |
width | Area width (px, 0 = to the window edge) | Number; 0 | Search 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. |
height | Area height (px, 0 = to the window edge) | Number; 0 | Search area height in pixels. 0 or less: up to the window edge. The same rules as width. |
wait | Wait in ms before capturing window | Number; 0 | Milliseconds 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.
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
select | Target coordinate selections | Click; Click | Click: the center of the match. Offset: the top-left corner of the match plus offset and offset. Coordinates are screen pixels. |
offset | Horizontal offset | Number; 0 | For Offset only: pixels to the right. A negative value goes left. |
offset | Vertical offset | Number; 0 | For Offset 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
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
action | Action to take on target coordinates | Click; Leftclick | Optional. 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
| Output | Type | Meaning and binding |
|---|---|---|
x | Number | The screen X of the point: the center of the match, or its top-left corner plus the offsets. Save it in a Number variable. |
y | Number | The 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.
Find window in window (imageRecognitionFindWindowImageInWindowImage)
Find a saved window capture in a visible window. It works the same as Find image in window.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
action | Action to take on target coordinates | Click; Leftclick | Optional. 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
| Output | Type | Meaning and binding |
|---|---|---|
x | Number | The screen X of the point: the center of the match, or its top-left corner plus the offsets. Save it in a Number variable. |
y | Number | The 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.
Conditions
Image file is found in image file (imageRecognitionFileImageExistInFileImage)
true when a saved image is found in an image file.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Select target image (needle) | String; "" | Required. A saved image file, such as samples/. |
source | Select source image (haystack) | String; "" | Required. The image file to search in, such as samples/. |
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.
Image file is found in window (imageRecognitionFileImageExistInWindowImage)
true when a saved image is found in a visible window.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Select target image (needle) | String; "" | Required. A saved image file, such as samples/. |
has | If image is found, click on it | Boolean; false | Optional. 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.
Image file is not found in image file (imageRecognitionFileImageNotExistInFileImage)
true when a saved image is not found in an image file.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Select target image (needle) | String; "" | Required. A saved image file, such as samples/. |
source | Select source image (haystack) | String; "" | Required. The image file to search in, such as samples/. |
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.
Image file is not found in window (imageRecognitionFileImageNotExistInWindowImage)
true when a saved image is not found in a visible window.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Select target image (needle) | String; "" | Required. A saved image file, such as samples/. |
has | If image is found, click on it | Boolean; false | Optional. 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.
Window is found in image file (imageRecognitionWindowImageExistInFileImage)
true when a saved window capture is found in an image file.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
source | Select source image (haystack) | String; "" | Required. The image file to search in, such as samples/. |
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.
Window is found in window (imageRecognitionWindowImageExistInWindowImage)
true when a saved window capture is found in a visible window.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
has | If image is found, click on it | Boolean; false | Optional. 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.
Window is not found in image file (imageRecognitionWindowImageNotExistInFileImage)
true when a saved window capture is not found in an image file.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
source | Select source image (haystack) | String; "" | Required. The image file to search in, such as samples/. |
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.
Window is not found in window (imageRecognitionWindowImageNotExistInWindowImage)
true when a saved window capture is not found in a visible window.
Inputs
| Input | Editor field | Type and runtime default | Use |
|---|---|---|---|
target | Target image (needle) | String; "" | Required. A saved image file, such as samples/. |
has | If image is found, click on it | Boolean; false | Optional. 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.