Lore

If it's worth remembering, it's worth writing down, if I find the time, and remember...

User Tools

Site Tools


imagesearch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
imagesearch [2018/04/05 13:34] – [Download] thekojukinatorimagesearch [2018/05/10 15:09] (current) thekojukinator
Line 1: Line 1:
-====== Image Search with AutoIt ======+====== ImageSearch with AutoIt ======
  
 ===== Overview ===== ===== Overview =====
  
-For years, I've been using [[https://www.autoitscript.com|AutoIt]] to accomplish all sorts of automation, and it has proven to be very capable toolHoweverone feature it is missing, which I recently found necessary, is //image search//EssentiallyI wanted to be able to look for something on the screen that matched an image, and, if possible, with tolerance for imperfect matches.+needed the ability for [[https://www.autoitscript.com|AutoIt]] to find something on the screen matching reference imageUnfortunatelythis is not an available built-in feature. There are functions available for checking individual pixelsbut no way to match groups of pixels or images.
  
-After some time searching around, ran in to [[https://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/?page=4|this thread]], which pretty much took me 95% of the way to my desired solution. The key is the [[https://www.autohotkey.com/docs/commands/ImageSearch.htm|AutoHotkey ImageSearch]] function. Someone capable extracted the //ImageSearch// function from the //AutoHotkey// and packed it up in to convenient DLLs, this started the ball rolling. With the contributions of various forum users, //UDF// ((//User Defined Functions// in AutoIt, usually collected in to a .au3 library.)) library was put together that acts as a wrapper for the //ImageSearch// function, which was then packaged with all the necessary DLLs for convenience.+found a solution in [[https://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/?page=4|this thread]]. The key is the [[https://www.autohotkey.com/docs/commands/ImageSearch.htm|AutoHotkey ImageSearch]] function. Someone extracted the **ImageSearch** code from //AutoHotkey//packed it up in to convenient DLLs, and put together **UDF** library that acts as a wrapper.
  
-Missing from the functions was the ability to search within a specific window. Instead, the choices were to search the entire desktop or a specified area. modified the code and added an optional parameter for a window handle, which will supply coordinates and dimensions for the search area. I also made the //tolerance// parameter optional, defaulting to exact match if omitted.+took the **UDF** library and made the following improvements to it:
  
-===== Syntax =====+  * Updated relevant functions to return an array of ''[x,y]'' coordinates on success, and ''False'' on failure. Original search functions returned ''True/False'' success status, while coordinate results were stored in external variables passed in by reference. 
 +  * Updated relevant functions with an extra parameter for a window handle, making it possible to limit the search area to the boundaries of a specified window. 
 +  * Added the ability to handle multi-monitor desktops by re-defining desktop boundaries in to new global variables ''desktopLeft'', ''desktopTop'', ''desktopRight'', ''desktopBottom'', ''desktopWidth'', and ''desktopHeight''.
  
-Coming soon™...+===== Example =====
  
-I started working on the syntax section, and decided to build a script with some examples, and then got carried away with improving the library. As it came, the functions returned coordinates by using pre-defined global variables that they took by reference and updatedI thought this was silly, so I adjusted them to properly return two-coordinate arrays on success. Also, while experimenting I realized that //AutoIt// doesn't have built-in macros or constants for the virtual desktop area of multiple monitorsso I figured out how to deal with that. +<code autoit> 
- +; Include the ImageSearch library 
-I need to polish things upcreate the example scriptre-upload the package, and then update this page.+#include ".\ImageSearch\ImageSearch.au3" 
 +; This will be the target image file to search for 
 +Local $target = "DemoTarget.png" 
 +; Declare an init a variable to hold the search result 
 +Local $result = False 
 +; Find the image across the entire desktop 
 +$result = _ImageSearch($target1) 
 +; If foundmove the mouse to it 
 +If IsArray($result) Then MouseMove($result[0]$result[1]) 
 +</code>
  
 ===== Download ===== ===== Download =====
  
-{{:imagesearch.7z|ImageSearch}} is my updated package. It includes the original //ImageSearch// and //MSVC// DLLs, along with the updated //ImageSearch.au3// library.+I've put it up on [[https://github.com/TheKojukinator/ImageSearch|GitHub]].
  
 {{tag>computing scripting autoit}} {{tag>computing scripting autoit}}
imagesearch.1522949660.txt.gz · Last modified: 2018/04/05 13:34 by thekojukinator