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/04 11:51] 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 [[https://www.autohotkey.com/docs/commands/ImageSearch.htm|AutoHotkey]]'s //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 some other users, //UDF// ((User Defined Function library, in AutoIt.)) with wrapper functions was put together, and 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 wrapper 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.+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 ===== 
 + 
 +<code autoit> 
 +; Include the ImageSearch library 
 +#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($target, 1) 
 +; If found, move the mouse to it 
 +If IsArray($result) Then MouseMove($result[0], $result[1]) 
 +</code>
  
 ===== Download ===== ===== Download =====
  
-{{:imagesearch.7z|ImageSearch}} is the package with the original DLLs, and my modified //ImageSearch.au3// include library.+I've put it up on [[https://github.com/TheKojukinator/ImageSearch|GitHub]].
  
 {{tag>computing scripting autoit}} {{tag>computing scripting autoit}}
imagesearch.1522857108.txt.gz · Last modified: 2018/04/04 11:51 by thekojukinator