Jump to content

Image Search Library


kangkeng
 Share

Recommended Posts

If anyone wants to use this in C#, here is how I did it:

    class ImageHelper
    {
        [DllImport("ImageSearchDLL.dll.32bit")] //or 64bit as you choose
        private static extern IntPtr ImageSearch(int x, int y, int right, int bottom, [MarshalAs(UnmanagedType.LPStr)]string imagePath)
 

...and then later on
 
            IntPtr result = ImageSearch(top, left, right, bottom, imagepath);
            String res = Marshal.PtrToStringAnsi(result);


            if (res[0] == '0') return null;//not found

            String[] data = res.Split('|');

            //0->found, 1->x, 2->y, 3->image width, 4->image heigth
            resX = int.Parse(data[1]);
            resY = int.Parse(data[2]);
Edited by sesk
Link to comment
Share on other sites

  • 2 months later...
  • 4 months later...

I have tried for the past few days, but cannot get this working.

I've isolated my code to literally just look for a black square of pixels on my black desktop background, but it always returns 0. (no pun intended)

Has anyone had any recent success with _imagesearch ? 

If so, please post a small snippet of code that you can confirm will return 1, so i can run it on my machine, and see if there is some wider systemic problem.

Edited by seanbrockest
Link to comment
Share on other sites

  • 1 month later...

Here is my first test script for _imageSearch

#include <ImageSearch.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{ESC}", "Terminate")
$ImgWindowsOrange = "c:\1.bmp"
$X = 0
$Y = 0

Main()
Func Main()
While 1
    $Found = _ImageSearch($ImgWindowsOrange, 0, $X, $Y, 0)
    If $Found = 1 Then
        MsgBox(0,"Found", $x & " " & $Y)
    else
        Sleep(250)
    EndIf
WEnd
EndFunc

Func Terminate()
    Exit 0
EndFunc

When I run the above I am getting a (44) error in the console:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\user\Desktop\test1.au3" /UserParams    
+>18:36:09 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\user\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\user\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\user\Desktop\test1.au3
+>18:36:09 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\user\Desktop\test1.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.:
if $result[0]="0" then return 0
if $result^ ERROR
->18:36:09 AutoIt3.exe ended.rc:1
+>18:36:09 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 0.3097

How can I fix this?

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Add this line to the top of your script - #AutoIt3Wrapper_UseX64=n

The DLL appears to be a 32 bit version.

NOTE: BTW, you probably could have troubleshot this yourself without asking the question if you'd taken 10 seconds to add some debugging to the UDF and/or your script. I found out that it won't run as a 64 bit process by finding out that the DLLCall,  in the previous line to your error, returned -1 meaning the DLL can't be used. Added the line above and that fixed the issue. Also, if you don't have the DLL in your script directory you're going to get the same error, the UDF uses a relative path for the dll filename.

Edited by BrewManNH

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

Link to comment
Share on other sites

Add this line to the top of your script - #AutoIt3Wrapper_UseX64=n

The DLL appears to be a 32 bit version.

NOTE: BTW, you probably could have troubleshot this yourself without asking the question if you'd taken 10 seconds to add some debugging to the UDF and/or your script. I found out that it won't run as a 64 bit process by finding out that the DLLCall,  in the previous line to your error, returned -1 meaning the DLL can't be used. Added the line above and that fixed the issue. Also, if you don't have the DLL in your script directory you're going to get the same error, the UDF uses a relative path for the dll filename.

 

The Dll file is in the script directory C:Program Files (x86)Autoit3Include. When I type _ImageSearch in Scite I am not getting the visual helper popup screen that tells me what I need to put in for the function to run which makes me think that the AU3 file is in the wrong place.

Is there a 64 bit version of this DLL file out there somewhere?

Regarding the troubleshooting, I don't know how to go about doing that even though I just read what you did. Also since this isn't in the installation of autoit by default I want a google searchable solution  so others can get the answer without asking.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

#AutoIt3Wrapper_UseX64=n
#include <ImageSearch.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{ESC}", "Terminate")
$ImgWindowsOrange = "c:\1.bmp"
$X = 0
$Y = 0

Main()
Func Main()
While 1
    $Found = _ImageSearch($ImgWindowsOrange, 0, $X, $Y, 0)
    If $Found = 1 Then
        MsgBox(0,"Found", $x & " " & $Y)
    else
        Sleep(250)
    EndIf
WEnd
EndFunc

Func Terminate()
    Exit 0
EndFunc

Console Output:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Users\user\Desktop\test1.au3" /UserParams    
+>19:19:00 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\user\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\user\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.10.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\user\Desktop\test1.au3
+>19:19:00 AU3Check ended.rc:0
>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\user\Desktop\test1.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.:
if $result[0]="0" then return 0
if $result^ ERROR
->19:19:00 AutoIt3.exe ended.rc:1
+>19:19:00 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 0.3169

Still doing the same thing. Do you mean put the #AutoIt3Wrapper_UseX64=n at the top of the ImageSearch.au3 file?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Is the DLL in the same folder as the imagesearch UDF file?

Have you tried troubleshooting this yourself to see where it's failing?

Add some consolewrites/msgboxes in the ImageSearch UDF file where it's failing to see why it gives you that error message instead of just reposting your script and telling us it still doesn't work. Scite4AutoIt3 comes with a handy debugging hotkey (CTRL+D) that will let you see what values a variable holds as the script is running. Click on the variable name, and hit CTRL+D and then save the file, and run your script.

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

Link to comment
Share on other sites

  • 3 weeks later...

I havent used imagesearch yet but tested a sample. Currently no 64bit pc on my place.

Question:

I wanted to know if i compiled my script and use it to other pc (which autoit never installed on it).. will the ImageSearchDll.dll required to be copied to those pc?

:P " Loved It ! " :wub:

Link to comment
Share on other sites

I havent used imagesearch yet but tested a sample. Currently no 64bit pc on my place.

Question:

I wanted to know if i compiled my script and use it to other pc (which autoit never installed on it).. will the ImageSearchDll.dll required to be copied to those pc?

Yes.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

#include <ImageSearch.au3>                                       ;include the .au3 file "ImageSearch" (location for file = AutoIt3\Include Folder)
;                                                                ;also needed for this script .dll file "ImageSearchDLL" (location for file = Windows/System32)
;                                                                ;from both files are (.au3, .dll) are diffrent versions 32-bit and 64-bit

HotKeySet("s", "checkForImage")                                  ;shortcut = S, for calling the "checkForImage" function

global $y = 0, $x = 0

Func checkForImage()                                             ;function called "checkForImage"
Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)     ;imagename, resultposition mouse, location image, tolerance
If $search = 1 Then                                              ;when search = 1 (image is found)
MouseMove($x, $y, 1)                                             ;move the mouse to location image, by speed of 10-1 (10 = slow, 1 = fast)
Exit                                                             ;close script
EndIf                                                            ;closing to the 'If'
EndFunc                                                          ;that all happend stop function

while 1                                                          ;while doing above
sleep(200)                                                       ;sleep 200 miliseconds (1000 = 1 second)
WEnd

'?do=embed' frameborder='0' data-embedContent>> by Centrally

works for me 64bit Windows 7  :thumbsup:

Link to comment
Share on other sites

  • 3 weeks later...

While 1
    $result = _imagesearch("tools/close.bmp", 1, $x, $y, 50)
    If $result = 1 Then
        MouseClick("left", $x, $y)
    EndIf
    $result2 = _imagesearch("tools/close2.bmp", 1, $x, $y, 50)
    If $result2 = 1 Then
        MouseClick("left", $x, $y)
    EndIf
    $result3 = _imagesearch("tools/close3.bmp", 1, $x, $y, 50)
    If $result3 = 1 Then
        MouseClick("left", $x, $y)
     EndIf
     $result4 = _imagesearch("tools/close4.bmp", 1, $x, $y, 50)
    If $result = 1 Then
        MouseClick("left", $x, $y)
     EndIf
     $result5 = _imagesearch("tools/close5.bmp", 1, $x, $y, 50)
    If $result = 1 Then
        MouseClick("left", $x, $y)
    EndIf

why is this script presing me the variable multiple times? how can i add a short sleep after the click if image was found so that the speed of the script is not reduced

Link to comment
Share on other sites

 

why is this script presing me the variable multiple times? how can i add a short sleep after the click if image was found so that the speed of the script is not reduced

Not sure I understand, but you could start by adding a short sleep after the click.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • 7 months later...
#include <ImageSearch.au3>                                       ;include the .au3 file "ImageSearch" (location for file = AutoIt3\Include Folder)
;                                                                ;also needed for this script .dll file "ImageSearchDLL" (location for file = Windows/System32)
;                                                                ;from both files are (.au3, .dll) are diffrent versions 32-bit and 64-bit

HotKeySet("s", "checkForImage")                                  ;shortcut = S, for calling the "checkForImage" function

global $y = 0, $x = 0

Func checkForImage()                                             ;function called "checkForImage"
Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)     ;imagename, resultposition mouse, location image, tolerance
If $search = 1 Then                                              ;when search = 1 (image is found)
MouseMove($x, $y, 1)                                             ;move the mouse to location image, by speed of 10-1 (10 = slow, 1 = fast)
Exit                                                             ;close script
EndIf                                                            ;closing to the 'If'
EndFunc                                                          ;that all happend stop function

while 1                                                          ;while doing above
sleep(200)                                                       ;sleep 200 miliseconds (1000 = 1 second)
WEnd

'?do=embed' frameborder='0' data-embedContent>> by Centrally

works for me 64bit Windows 7  :thumbsup:

 

Can you share your DLL and ImageSearch.au3?

I cant make this works in Windows 8.1 64 :(

Edited by keteflips
Link to comment
Share on other sites

  • 2 weeks later...

Hello,

I have problems to make this dll works with a python script. With autoit, all is ok and it works like a charm but i would like to use it with python :/

Here is my script :

import ctypes

dllFunc = ctypes.cdll.LoadLibrary('ImageSearchDLL.dll')
dllFunc.ImageSearch.argtypes = (ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_char_p,)
dllFunc.ImageSearch.restype = ctypes.c_char_p

_result = dllFunc.ImageSearch(0, 0, 1920, 1080, b"myPic.bmp")
result = _result.value
print(result)

The python debugger show me : "ValueError: Procedure called with not enough arguments (20 bytes missing) or wrong calling convention".

Any help will be appreciated. Thank you.

Edited by periaz
Link to comment
Share on other sites

  • 5 months later...
  • Developers

Download seems to be broken.

Guess you are referring to the original post made in 2008 by somebody that hasn't been around since 2011? 
I rest my case .. ')

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...