CompareBitmaps
CompareBitmaps>bitmap_file_1,bitmap_file_2,result
Compares two bitmap files and returns the percentage match. If the two files are not of the same dimension then result will be -1.
Abbreviation: CPB
See also: GetScreenRes FindImagePos ScreenCapture WaitScreenImage
CompareBitmaps Example
GetScreenRes>ScreenW,ScreenH
ScreenCapture>0,0,ScreenW,ScreenH,d:\current_screen.bmp
CompareBitmaps>d:\required_screen.bmp,d:\current_screen.bmp,match
If>match=100
MessageModal>Screens Match
Endif
FindImagePos
FindImagePos>needle_bitmap,haystack,tolerance,return_offset,X_Array,Y_Array,NumFound[,MatchAlgorithm]
Scans a haystack image looking for occurrences of needle_bitmap. needle_bitmap is usually a small image such as an image of a button or other GUI component captured at design time, and haystack would be a screen image.
needle_bitmap should be a fully qualified path to a bitmap or png file (see MatchAlgorithm type below for supported image types).
haystack can be set to one of the following values:
- A bitmap/png file (e.g. %SCRIPT_DIR%\haystack.bmp) (see MatchAlgorithm type below for supported image types).
- SCREEN - this causes the entire screen to be scanned
- WINDOW:title where title is a window title (e.g. WINDOW:Untitled - Notepad)
To use exact matching set MatchAlgorithm to EXACT.
To use Correlation Coefficient algorithm set MatchAlgorithm to CCOEFF. This algorithm uses a template matching system attempting to find similarities in images rather than comparing pixels precisely. It is therefore able to find images even if they are not exactly the same and will therefore cope with differences in bit depth, different versions of images across different versions of Windows and different fonts, etc, making image recognition scripts more portable and less likely to fail should the environment change.
The use of the tolerance parameter varies depending on the MatchAlgorithm used.
- CCOEFF:Tolerence should be given a value between 0 and 1 where 1 is a precise match and 0 is the least precise. A value of 0.7 is recommended and should allow for subtle variations in the images and works best for portability. The lower the value the more likely false positives will be observed. With CCOEFF matching only one match (if any) is returned - the most likely candidate. CCOEFF will work with bitmap or png files.
- EXACT: For exact matching tolerance specifies the color tolerance. If tolerance is zero the pixel colors must match exactly. Tolerance can be set to a value between 0 and 255. If larger than zero the red, green and blue values of the pixels in bitmap_to_scan are checked to see if they are within the tolerance specified (color value + or - tolerance). Smaller values match less and larger values match more. EXACT matching may return more than 1 match if there are more than 1 exact matches in the target area. EXACT can only work with bitmap files.
Each method has benefits and drawbacks. CCOEFF is more intelligent and more tolerant but is slower and will return only one match. EXACT is faster and can return multiple matches but is precise and therefore less portable and will not cope with changes.
To ensure backward compatibility EXACT matching will be used if MatchAlgorithm is omitted. This ensures old scripts will work as they used to.
return_offset is used to determine which coordinates should be returned and can be one of the following:
- 0 Top left position of located image within bitmap_to_scan. In other words X, Y is the top left corner of needle_bitmap within haystack
- 1 Center: X,Y will be set to the center of the located image within the main haystack image.
- 2 Top right
- 3 Bottom left
- 4 Bottom right
- 5 Middle top
- 6 Middle bottom
- 7 Middle left
- 8 Middle right
X_Array is the name of an array to store the X coordinates of each match. If using CCOEFF matching (the default) only the most likely result is returned and so there will be only one result in X_Array_0 if a match is found. If using EXACT matching multiple results may be returned. The first match is stored in X_Array_0, the second in X_Array_1, etc.
Y_Array is the name of an array to store the Y coordinates of each match. If using CCOEFF matching (the default) only the most likely result is returned and so there will be only one result in X_Array_0 if a match is found. If using EXACT matching multiple results may be returned. The first match is stored in Y_Array_0, the second in Y_Array_1, etc.
NumFound returns the number of matches found. If an error is encountered NumFound will be set to -1. E.g. if the needle image is larger than the haystack image, NumFound will be set to -1.
Note:
Note that if haystack is SCREEN or a WINDOW the x and y positions returned are absolute screen positions and can be used directly with MouseMove to move the mouse to the found position.Advanced (If using EXACT matching): By default FindImagePos now scans ALL pixels in each matching rectangle on needle_bitmap. If you wish to scan only a small set of random pixels (and thereby speed up searching) set FIP_SCANPIXELS to that number, e.g. FIP_SCANPIXELS=100. To set back to all set FIP_SCANPIXELS=ALL.
Abbreviation: FIP
See also: GetScreenRes CompareBitmaps ScreenCapture WaitScreenImage
FindImagePos Example
FindImagePos>d:\today_button.bmp,SCREEN,0.7,1,X,Y,NumFound,CCOEFF
If>NumFound>0
MouseMove>X_0,Y_0
Endif
GetPixelColor
GetPixelColor>X,Y,result
Returns the pixel color of the specified screen coordinate. Enter the coordinates in X and Y, and specify a variable to store the pixel color in.
Abbreviation : GPC
See also: WaitPixelColor GetRectCheckSum WaitRectChanged
GetPixelColor Example
GetPixelColor>652,355,PC
Message>Pixel Color is : %PC%
GetRectCheckSum
GetRectCheckSum>TLX,TLY,BRX,BRY,result_value
When passed the top left and bottom right screen coordinates of a rectangle, this function returns the checksum of that rectangle. The checksum is based on the color and position in the rectangle of each individual pixel. The checksum is returned in the variable result_value.
This command will allow for waiting for a specific part of the screen to become equal to a known graphic. Use the command when the graphic to be compared against is present to determine it's checksum. The example below shows a loop which will cause the script to wait until the rectangle contains the required graphic.
- TLX - Top Left corner X coordinate
- TLY - Top Left corner Y coordinate
- BRX - Bottom Right corner X coordinate
- BRY - Bottom Right corner Y coordinate
This function was optimized in version 10 to improve performance and now operates very quickly, taking around 0.1 second to scan a 500x500 area of screen. However, on some systems it may consume a lot of CPU cycles in the process. If you need to force the function to yield to the system more you can set GRC_YIELD to 1, but this will have the side effect of slowing the function down, as it gives over CPU time to other processes.
Abbreviation : GRC
See also: WaitRectChanged, WaitPixelColor , GetPixelColor
GetRectCheckSum Example
Label>waitforit
GetRectCheckSum>10,10,15,15,cs
If>cs=6.20066481623195E16,Done
Goto>waitforit
Label>Done
Message>There You Go
GetScreenRes
GetScreenRes>Width,Height
Returns the dimensions of the primary monitor.
Abbreviation : GSR
See also: CompareBitmaps, FindImagePos, ScreenCapture, WaitScreenImage.
GetScreenRes Example
GetScreenRes>X,Y
ScreenCapture
ScreenCapture>X1,Y1,X2,Y2,Filename
Captures a portion of the screen to a .BMP (bitmap) or .JPG (jpeg) file and (by default) to the clipboard.
X1 and Y1 represent the upper left corner of the screen area to be copied.
X2 and Y2 represent the lower right corner of the screen area to be copied.
Filename is the name of the file to create and can end with a .BMP, .PNG or .JPG extension.
ScreenCapture returns a variable called SCREENCAP_RESULT which will contain one of the following values:
- 0: Successful
- 1: Invalid file type specified. Valid file types are .BMP, .PNG or .JPG
- 2: Unable to save image to specified file
- 3: No filename specified
- 4: Nonsensical coordinates specified (e.g. top >= bottom or left >= right)
To prevent ScreenCapture saving to the clipboard set the SCREENCAP_CLIPBOARD variable to 0.
Abbreviation: SCP
See also: CompareBitmaps, FindImagePos, GetScreenRes, WaitScreenImage.
ScreenCapture Example
ScreenCapture>10,10,200,200,d:\mypic.bmp
WaitPixelColor
WaitPixelColor>ColorCode,X,Y,Timeout
This command causes script to wait until the pixel colour at the specified pixel coordinates changes to the colour specified in ColorCode. If it doesn't change to that colour within the number of seconds specified in Timout, the command stops waiting and the variable WPC_RESULT is set to FALSE. WPC_RESULT is TRUE if the command terminated because the colour changed to the specified colour within the specified time. if Timeout is set to 0, the command will wait indefinitely.
To determine the correct colour code to use, click the drop down menu button next to the cursor position monitor on the macro properties form. From the drop down menu select 'Pixel Color' and the pixel colour of the current mouse cursor position will be added to the display along with the X and Y coordinates. Now you can determine the correct colour code of any pixel on the screen.
Abbreviation : WPC
See also: CompareBitmaps, FindImagePos, GetScreenRes, WaitScreenImage
WaitPixelColor Example
WaitPixelColor>16777215,652,355,10 Message>WPC_RESULT
WaitRectChanged
WaitRectChanged>TLX,TLY,BRX,BRY,Timeout
This command causes script to wait until the image bound by the specified pixel coordinates changes. If it doesn't change within the number of seconds specified in Timeout, the command stops waiting and the variable WRC_RESULT is set to FALSE. WRC_RESULT is TRUE if the command terminated because the image changed within the specified time. if Timeout is set to 0, the command will wait indefinitely.
- TLX - Top Left corner X coordinate
- TLY - Top Left corner Y coordinate
- BRX - Bottom Right corner X coordinate
- BRY - Bottom Right corner Y coordinate
This function was optimized in version 10 to improve performance and now operates very quickly, taking around 0.1 second to scan a 500x500 area of screen. However, on some systems it may consume a lot of CPU cycles in the process. If you need to force the function to yield to the system more you can set GRC_YIELD to 1, but this will have the side effect of slowing the function down, as it gives over CPU time to other processes.
Abbreviation : WRC
WaitRectChanged Example
WaitRectChanged>10,10,100,100,10 Message>WRC_RESULT
WaitScreenImage
WaitScreenImage>BitmapFile[,Tolerance[,MatchAlgorithm]]
Waits until the image in BitmapFile is found on the screen.
It is recommended to use the Image Recognition Wizard to create WaitScreenImage code.
Returns the number of occurrences found on the screen in the WSI_RESULT variable.
For an explanation of Tolerance and MatchAlgorithm please see FindImagePos. WaitScreenImage is effectively a wrapper for a loop containing FindImagePos.
The system variable WSI_TIMEOUT can be used to set the number of seconds after which this command should timeout. If set to zero (the default) the timeout will not occur and the command will continue indefinitely. If WSI_TIMEOUT is used, WSI_TIMEDOUT will indicate whether or not the command ended successfully. If it timed out WSI_TIMEDOUT will be set to TRUE otherwise, if the image was found within the time out period it will be set to FALSE. If the command times out WSI_BITMAP will contain the path of BitmapFile. This is useful if using a global event handler for WSI_TIMEDOUT and you nee to know which WaitScreenImage timed out.
Abbreviation: WSI
WaitScreenImage Example
WaitScreenImage>d:\today_button.bmp
MessageModal>FoundIt
Comments
0 comments
Please sign in to leave a comment.