Jump to content
Centrally

ImageSearch Usage Explanation

Recommended Posts

ileandros

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%

  • Like 2

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
VelvetElvis

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?

  • Like 1

Share this post


Link to post
Share on other sites
VelvetElvis

<Bump> Anyone know the difference in these .dll's?

  • Like 1

Share this post


Link to post
Share on other sites
techbard

nice work! thx~

  • Like 1

Share this post


Link to post
Share on other sites
kjensen

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 :)

  • Like 1

Share this post


Link to post
Share on other sites
romanais

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)
  • Like 1

Share this post


Link to post
Share on other sites
Centrally

It is typo, and I got no idea how that line ended there, anyway thanks for pointing it out, I fixed it now.

Edited by Centrally
  • Like 1

Share this post


Link to post
Share on other sites
Centrally

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?

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.
  • Like 1

Share this post


Link to post
Share on other sites
TimCunningham

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.

  • Like 1

Share this post


Link to post
Share on other sites
Amiekbir

Hi i did what u said but i am unable to use the imagesearch function. I used the 64 bit one but now working.

  • Like 1

Share this post


Link to post
Share on other sites
Amiekbir

i used the 32 bit too same result.

  • Like 1

Share this post


Link to post
Share on other sites
MythEdge

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?

  • Like 1

Share this post


Link to post
Share on other sites
tbodine88

I added this code in _imageSearchArea

Func _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.

  • Like 1

tbodine

Share this post


Link to post
Share on other sites
tbodine88

I added code to test that DLL loads and runs and complain if not:

Func _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


tbodine

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites
asfaloth

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

Share this post


Link to post
Share on other sites
Ashen

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?

  • Like 1

Share this post


Link to post
Share on other sites
sersam

I'm using the 32 bit version. But it's not working. Reason: AutoIT to stop working.

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • kuhicop
      By kuhicop
      Hello, I need to find an image on screen and return it's position left, top, right, botton.
      I'm using the ImageSearch function but it only returns 1 or 0.
      Any ideas? Thanks!
    • Errious
      By Errious
      Hello,
      maybe i am just tired or i did not understand exactly how to use ImageSearch for different pictures, but i tried now a few things with my example script and only the first part is working.
      Explaining what i try to do, at work we have a programm running which has three different states, they are visible but sometimes the statuses of the process is not running and to avoid a long time without progress of the programm i searched to get a way to have a better visible notification as existing, so there is grey as work in progress, orange for not running and red for aborted, now when the states are changing i would like to receive a little window that is just telling the actual status.
      #include <ImageSearch2015.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> $x1=0 $y1=0 While 1 sleep(100) $image1 = _ImageSearch("red.png", 1,$x1,$y1,0) If $image1 = 1 then SplashTextOn ( "", "RED !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() sleep(100) EndIf $image2 = _ImageSearch("orange.png", 1,$x1,$y1,0) If $image2 = 1 Then SplashTextOn ( "", "Orange !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() sleep(100) EndIf $image3 = _ImageSearch("grey.png", 1,$x1,$y1,0) If $image3 = 1 Then SplashTextOn ( "", "Grey !" , 100 , 50 , 1800 , 220 , $DLG_TEXTLEFT, "Arial" , 12 , 500 ) Sleep(1000) SplashOff() EndIf WEnd As i said before, part one to receive the state for aborted is working, so i get the splash window for this, but what do i miss for the other two?
      I put the While statement in for continuously running as long it is needed when the program is in use, but i believe i missed something.
    • VIP
      By VIP
      Use MouseClick()  mybe must/need:
      #RequireAdmin  
      DLL incuded on script!
      ; #INDEX# ================================================================================================= ; Title .........: ImageSearch ; AutoIt Version : 3.x ; Language ......: English ; Description ...: Check image Appears or Not and Return the position of an image on the desktop ; Author(s) .....: Dao Van Trong - TRONG.LIVE ; ================================================================================================= ; #CURRENT# ================================================================================================= ; _ImageSearch ; _ImageSearch_Area ; _ImageSearch_Wait ; _ImageSearch_WaitArea ; ================================================================================================= ;=============================================================================== ; ; Author:...........: AutoIT VietNam : Dao Van Trong - TRONG.LIVE ; Description:......: Check image Appears or Not ; Find and return the position of an image on the desktop ; Syntax:........... _ImageSearch_Area, _ImageSearch ; Parameter(s):..... $_ImagePath: The image to locate on the desktop ; May be a list of image by delimited by "|" ; i.e: $_ImagePath = "image1.bmp|image2.bmp|image3.bmp" ; $P_x1 $P_y1: Position of 1st point ; $P_x2 $P_y2: Position of 2nd point - Default is last botton right of desktop ; $_Tolerance: 0 for no tolerance (0-255). Needed when colors of image differ from desktop. e.g GIF ; $_CenterPos: boolen. True will return $array[1] x $array[2] is center of image found. ; False will return top-left position ; Return Value(s):.. Return an array has 3 item ; On Success: $array[0] 1 ; On Failure: $array[0] 0 ; DLL not found or other error: $array[0] -1 ; $array[1] x $array[2]: position of image what found on desktop ; ; Note:............. Use _ImageSearch to search the entire desktop ; _ImageSearch_Area to specify a desktop region to search ; $_ImagePath with more item need more time appear on screen before function can detect. ; Decrease sleep time in the loop to detect faster. But less performance. I.e CPULoad increased ; ;=============================================================================== EG:
      #include "_ImageSearch.au3" #include "_ImageSearch_Debug.au3" #RequireAdmin HotKeySet("{Esc}", "_Exit") ; Press ESC for exit Func _Exit() Exit 0 EndFunc ;==>_Exit Global Const $Ask_On_Found = 1 Global Const $Mouse_Move_On_Found = 1 Global Const $Mouse_Click_On_Found = 0 Global $_Image_1 = @ScriptDir & "\example.bmp" ; First, use this function to create a file bmp, maybe a desktop icon for example') MsgBox(64 + 262144, 'ImageSearch', 'At first, create a file bmp,' & @CRLF & 'photos that will search on the screen!') _ImageSearch_Create_BMP($_Image_1) ConsoleWrite("! Search for images: " & $_Image_1 & @CRLF & '! Searching on the screen ...' & @CRLF) While 1 ToolTip('(Press ESC for EXIT) Searching ...', 1, 1) Local $return = _ImageSearch($_Image_1) If $return[0] = 1 Then ConsoleWrite('- Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF) If $Mouse_Move_On_Found Then MouseMove($return[1], $return[2]) If $Mouse_Click_On_Found Then MouseClick("left", $return[1], $return[2]) ToolTip('(Press ESC for EXIT) Image found:' & " X=" & $return[1] & " Y=" & $return[2], 1, 1) If $Ask_On_Found Then Local $ask = MsgBox(6 + 262144, 'Success', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2]) If $ask = 2 Or $ask = 3 Or $ask = 5 Or $ask = 7 Then Exit ;No, Abort, Cancel, and Ignore If $ask = 10 Then _ImageSearch_Create_BMP($_Image_1) ; Continue ;Try Again EndIf EndIf Sleep(200) WEnd  
       
      Video demo:
       
    • Nick3399
      By Nick3399
      I have loaded FastFind into my code and it takes a snapshot and creates a BMP file from it. 
      My issue is now I want to imagesearch from that BMP file (or snapshot memory) and look for a specific image from that image and get the coordinates from that. 
      I have looked at all the documentation but I cannot find anything to assist me.
       
      Does anyone have any idea?
    • tiye0405
      By tiye0405
      Hello,
      global $y, $x #RequireAdmin Global $Paused HotKeySet("{NUMPAD2}", "Pause") HotKeySet("{NUMPAD8}", "End") Opt("MouseClickDownDelay", 30) #include <ImageSearch2015.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <UpDownConstants.au3> #include <Misc.au3> Sleep(6000) Sleep(3000) $search1 = _WaitForImageSearch("goo.bmp", 30, 1, $x, $y, 10) If $search1 = 1 Then MouseMove(1500, 1500, 10) Sleep(100) MouseClick("right") Sleep(300) EndIf I've this script.
      The problem is that it work the way it is supposed to but doesnt work on a friends pc, even tho we have the same image search in C/programms(x86)/autoit3/include 
      and the same dll in system 32.
      When he starts the script on the desktop without having the "goo.bmp" file on his pc, the script finds it and right clicks the given location, while for me it doesnt and i have to open the folder with the "goo.bmp" picture in it.

      Im out of ideas on what could cause the problem.
      Any help?
      Thank you in advance
       
       
×