Popular Post Centrally Posted February 3, 2013 Popular Post Share Posted February 3, 2013 (edited) After having lot of issues myself with getting ImageSearch to work I decided to make topic with explanation how to proper use this script.Here is link of original topic at this topic: Credits to kangkeng for creating such useful piece of code.What is ImageSearch?It's script that find part of screen which you before defined with given image.When should I use ImageSearch?You should use it whenever it's not possible or unlikely that pixelsearch will give what you need.So how can I use ImageSearch and enjoy it's awesome benefits?First of all to avoid mostly caused problems I recompiled DLLs for both architectures which you can download at end of this post. When you pick your package you should place both ImageSearch.au3 and ImageSearch.dll inside script folder.Usage Example:First of all take picture of what you want to search for (print screen + paint + corp + save as bmp).Place that picture in script directory (I named my picture checkImage (checkImage.bmp is full name with extension). You must include ImageSearch.au3 in your script.ImageSearch.au3 consist of 2 Functions you can use: _ImageSearch and _ImageSearchAreaNote: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify a desktop region to searchValues to put in for _ImageSearch function (entire screen search)($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0)Values to put in for _ImageSearchArea function (you declare part of screen to be searched)($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance,$HBMP=0)Description of parameters from ImageSearch.au3 itself:; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0Example of my script using _ImageSearch ( entire screen search)#include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEndExample of my script using _ImageSearchArea #include <ImageSearch.au3> HotKeySet("p", "checkForImage") global $y = 0, $x = 0 Func checkForImage() local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0) If $search = 1 Then MouseMove($x, $y, 10) EndIf EndFunc while 1 sleep(200) WEndI would like to apologize if by writing this I offended any of member that thinks this script is too simple to even have it explained, it's just as me being new to autoIt it took me so much time getting around errors and making this script to work.Thanks for reading, if you bump on any problems using it post it here, I will try to help you fixing it and update topic for further reference.Download links:32bit: ImageSearch 32bit.rar64bit: ImageSearch 64 bit.rar Edited February 15, 2013 by Centrally ibrahem, MikahS, Alexxander and 9 others 10 2 Link to comment Share on other sites More sharing options...
ileandros Posted February 3, 2013 Share Posted February 3, 2013 Usually imagesearch library is used for game automatation. Pixel search as well. FF udf it's much more powerful I find. But none of them are trustable 100% knuxfighter and kcvinu 2 I feel nothing.It feels great. Link to comment Share on other sites More sharing options...
VelvetElvis Posted February 6, 2013 Share Posted February 6, 2013 I've used this for automating a daily job at work that refreshes +/- 35 reports daily with each one searching, and it hasn't missed a beat. I'm curious as to the difference in .dll files, compared to the one in the original post from 2008. Here's the two versions: Original ImageSearchDLL.dll 92k 2/28/2008 Your ImageSearchDLL.dll 77k 1/24/2010 Can you (or anyone else) tell me what the differences are? kcvinu 1 Link to comment Share on other sites More sharing options...
VelvetElvis Posted February 8, 2013 Share Posted February 8, 2013 <Bump> Anyone know the difference in these .dll's? kcvinu 1 Link to comment Share on other sites More sharing options...
techbard Posted February 14, 2013 Share Posted February 14, 2013 nice work! thx~ kcvinu 1 Link to comment Share on other sites More sharing options...
kjensen Posted February 14, 2013 Share Posted February 14, 2013 I think it's fine. I appreciate that I can use that now instead of merging Auto Hot Key/AutoIT type features. I look forward to re-writing some of my mcros to incorporate this and thank you again for the intro into Image search kcvinu and TinyCoopMan 2 Link to comment Share on other sites More sharing options...
romanais Posted February 15, 2013 Share Posted February 15, 2013 Hello, i think that there's a typo on your "Example of my script using _ImageSearchArea".With this line :local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0)Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0) kcvinu 1 Link to comment Share on other sites More sharing options...
Centrally Posted February 15, 2013 Author Share Posted February 15, 2013 (edited) It is typo, and I got no idea how that line ended there, anyway thanks for pointing it out, I fixed it now. Edited February 15, 2013 by Centrally kcvinu 1 Link to comment Share on other sites More sharing options...
Centrally Posted February 15, 2013 Author Share Posted February 15, 2013 I've used this for automating a daily job at work that refreshes +/- 35 reports daily with each one searching, and it hasn't missed a beat.I'm curious as to the difference in .dll files, compared to the one in the original post from 2008. Here's the two versions:Original ImageSearchDLL.dll 92k 2/28/2008Your ImageSearchDLL.dll 77k 1/24/2010Can you (or anyone else) tell me what the differences are?I'm not really sure about difference because I only compiled last source code I found, if you really want to find out what is different than try finding source code from 2008 and compare it to one from 2010. kcvinu 1 Link to comment Share on other sites More sharing options...
TimCunningham Posted March 8, 2013 Share Posted March 8, 2013 I was having trouble like you were having trouble. This topic is very helpful. I was working on this image search for hours and hours and I could not get it to work! I was able to find the droid I was looking for (heh) when I saved the image as a 24-bit BMP rather than 256 or 16-bit. Not sure why this is but I hope that helps someone. If it isn't working for you, try saving the picture as a different bmp file. kcvinu 1 Link to comment Share on other sites More sharing options...
Amiekbir Posted March 19, 2013 Share Posted March 19, 2013 Hi i did what u said but i am unable to use the imagesearch function. I used the 64 bit one but now working. kcvinu 1 Link to comment Share on other sites More sharing options...
Amiekbir Posted March 22, 2013 Share Posted March 22, 2013 i used the 32 bit too same result. kcvinu 1 Link to comment Share on other sites More sharing options...
MythEdge Posted March 28, 2013 Share Posted March 28, 2013 Hello and thank you for the tutorial. I have been trying to get this imagesearch function to work for weeks! I took your code and copied it exactly. Then I took ImageSearch.au3, imagesearchdll.dll and my script (Which is a new script file with your code) along with my checkImage.bmp and put them all into my working directory folder. I click the script, I click P and nothing happens but the script no longer runs. I get no error or anything. Did I miss something? kcvinu 1 Link to comment Share on other sites More sharing options...
tbodine88 Posted July 24, 2013 Share Posted July 24, 2013 I added this code in _imageSearchArea expandcollapse popupFunc _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP = 0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage If IsString($findImage) Then $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP) $err = @error Else $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findImage, "ptr", $HBMP) $err = @error EndIf Switch $err Case 1 ConsoleWriteError("unable to use the DLL file" & @CRLF) exit 1 Case 2 ConsoleWriteError('unknown "return type" ' & @CRLF) exit 1 Case 3 ConsoleWriteError('"ImageSearch" not found in DLL' & @CRLF) exit 1 Case 4 ConsoleWriteError('bad number of parameters' & @CRLF) exit 1 Case 5 ConsoleWriteError('bad parameter' & @CRLF) exit 1 EndSwitch ; If error exit If $result[0] = "0" Then Return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0], "|") $x = Int(Number($array[2])) $y = Int(Number($array[3])) If $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) $y = $y + Int(Number($array[5]) / 2) EndIf Return 1 EndFunc ;==>_ImageSearchArea I down loaded the 64 bit version, and I get the "unable to use the DLL file" error. I thought this might help some to debug. I don't have it working, but I'll try the 32 bit version even though I'm running 64 bit windows 7. kcvinu 1 Link to comment Share on other sites More sharing options...
tbodine88 Posted July 24, 2013 Share Posted July 24, 2013 I added code to test that DLL loads and runs and complain if not: expandcollapse popupFunc _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP = 0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage If IsString($findImage) Then $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP) $err = @error Else $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findImage, "ptr", $HBMP) $err = @error EndIf Switch $err Case 1 ConsoleWriteError("unable to use the DLL file" & @CRLF) exit 1 Case 2 ConsoleWriteError('unknown "return type" ' & @CRLF) exit 1 Case 3 ConsoleWriteError('"ImageSearch" not found in DLL' & @CRLF) exit 1 Case 4 ConsoleWriteError('bad number of parameters' & @CRLF) exit 1 Case 5 ConsoleWriteError('bad parameter' & @CRLF) exit 1 EndSwitch ; If error exit If $result[0] = "0" Then Return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0], "|") $x = Int(Number($array[2])) $y = Int(Number($array[3])) If $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) $y = $y + Int(Number($array[5]) / 2) EndIf Return 1 EndFunc ;==>_ImageSearchArea Using this I found that on my computer at work the 64 bit version of the DLL gives the error unable to use the DLL file The 32 bit version when used causes AutoIT to stop working. Bummer I sure did like this thing back in the old XP days. Regards tbodine88 Link to comment Share on other sites More sharing options...
BrewManNH Posted July 24, 2013 Share Posted July 24, 2013 Run the script as a 32 bit exe If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
asfaloth Posted August 3, 2013 Share Posted August 3, 2013 Hello, i tried this plugin and it work very well, but i cant understand one thing: if the image is in a folder located in the script folder, what is the code to make it look inside another folder instead of his own one? My english is bad, if you dont understand, i can try to reformulate the sentence xD Link to comment Share on other sites More sharing options...
Ashen Posted December 3, 2013 Share Posted December 3, 2013 Just a  small concern of mine about this whole deal: If, in order to use these functions, I am forced to use a DLL that I do not understand - what happens if in the future the DLL would need to be changed in order to work but no one knows how to change it? do all my scripts stop working forever? guestscripter 1 Link to comment Share on other sites More sharing options...
sersam Posted March 14, 2014 Share Posted March 14, 2014 I'm using the 32 bit version. But it's not working. Reason: AutoIT to stop working. Link to comment Share on other sites More sharing options...
BrewManNH Posted May 7, 2014 Share Posted May 7, 2014 The right side and bottom corner of the rectangle you want to search in. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now