Jump to content

ImageSearch Usage Explanation


Centrally
 Share

Recommended Posts

There's no loop, so it just ends.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • 3 months later...

Hello guys....Im trying to use Image search to search an image in web.....I tried using the above Image search dll. But this dll only works for images on my desktop and not in IE browser. Please help me to search an image in IE..

Link to comment
Share on other sites

  • 2 months later...
  • Developers
2 hours ago, Rossi46 said:

i have error as :  missing separator character before keyword.what is solution on that

Change line 2154 and you should be fine.

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

6 hours ago, Rossi46 said:

missing separator character before keyword

If you have downloaded the full Scite4AutoIt3 package you can just run the Tidy command and it will probably fix the formatting.

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

Regarding issues encountered when compiling the ImageSearch.au3 file, in addition to the issue pointed out by @Rossi46 above, I've also encountered additional issues when compiling that code with the current AutoIt release. They involve run-time errors due to undeclared variables, since my calling code requires that all variables be declared (this is not reported at compile time).

The variables in question are: (1) $right -- For some unknown reason, specifying that variable in the DllCall function is reported as undeclared, even though itt's properly declared in the outer function. There may be other work-arounds, but what worked for me was to specify a different input argument name, then declare $right and assign it the argument variable.

The other is more straightforward; the array variable $array was never declared within _ImageSearchArea(). Doing so solved my problem.

Here is a version with all the corrections I required:

#include-once
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; 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 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $arg_right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    Local $right = $arg_right
If IsString($findImage) Then
    Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP)
Else
    Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findImage, "ptr", $HBMP)
EndIf

    ; 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
    Local $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

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $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 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $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 the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP)
            if $result > 0 Then
                return $i
            EndIf
        Next
    WEnd
    return 0
EndFunc

 

Link to comment
Share on other sites

  • 2 months later...

Hi, is there a way to search for multiple images on the same fuction execution? Example down there is searching for 10 different pictures on the same window each loop, one imagesearch for each image to compare. Is there a way to do 1 imagesearch with all 10 to compare running 1x the imagesearch function? I need to know cause running the script like this i keep getting hundreds os microfreeze, more like a shutter effect while alt+tabbing and thats driving me crazy.

If its not possible, i'm planning in migrate to C# or Python to make my scripts with image search and stuff, do you guys recommend any of those?

If _ImageSearchArea($picture1, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture2, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture3, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture4, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture5, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture6, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture7, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture8, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture9, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 or _ImageSearchArea($picture10, 1, $searchwindow2Pos[0], $searchwindow2Pos[1], $searchwindow2Pos[0]+$searchwindow2Pos[2], $searchwindow2Pos[1]+$searchwindow2Pos[3], $picture2x, $picture2y, 96, 0) = 1 Then
                Beep(500, 1000)
                Sleep (120000)
            EndIf

 

Link to comment
Share on other sites

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

how do i get ImageSearch to work in a multiple monitor setup? it seems to work on my main monitor but can't find the image on my secondary monitor. here's my code:

 

#include <ImageSearch.au3>

HotKeySet("p", "checkForImage")

global $x = 0, $y = 0

Func checkForImage()
msgbox(0,"","running!")
Local $search = _ImageSearch('image.png', 1, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 0)
EndIf
EndFunc

while 1
sleep(200)
WEnd

 

Edited by dwaynek
Link to comment
Share on other sites

3 minutes ago, dwaynek said:

how do i get ImageSearch to work in a multiple monitor setup? it seems to work on my main monitor but can't find the image on my secondary monitor. here's my code:

 

#include <ImageSearch.au3>

HotKeySet("p", "checkForImage")

global $x = 0, $y = 0

Func checkForImage()
msgbox(0,"","running!")
Local $search = _ImageSearch('image.png', 1, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 0)
EndIf
EndFunc

while 1
sleep(200)
WEnd

 

nvm i used _ImageSearchArea() instead with negative starting values and that worked.

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

running this simple code:

 

#include <ImageSearch.au3>

   Local $findImage="10parsed.png";
   Local $center=1;
   Local $foundX=0,$foundY=0;
   Local $tolerance=10;
   _ImageSearch($findImage,$center,$foundX, $foundY,$tolerance);

it enters

Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $arg_right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP=0)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
    Local $right = $arg_right
If IsString($findImage) Then
    Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP)
Else
    Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findImage, "ptr", $HBMP)
EndIf

    ; If error exit
    if $result[0]="0" then return 0

then crash on the 

; If error exit
    if $result[0]="0" then return 0

line with the error
"C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3" (45) : ==> Subscript used on non-accessible variable.:

and when i run

ConsoleWrite(VarGetType($result));

it prints Int32 , and it contains 0.. 

guess that means the error-check code is somewhat broken (it should check if(result==0)  rather than if(result[0]==0)) and that there was an error?

Link to comment
Share on other sites

  • 1 month later...

I get error if I include ImageSearch.au3 in another folder than where my script is. Hard to explain folder structure so I uploaded a small example.

I think the path to ImageSearchDLL.dll is what gives error, but I tried changing it to a full path without any luck.

If IsString($findImage) Then
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
Else
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
EndIf
Link to comment
Share on other sites

  • Developers
33 minutes ago, spuuunit said:

I get error if I include ImageSearch.au3 in another folder than where my script is. Hard to explain folder structure so I uploaded a small example.

You are pretty persistent in not providing normal required information ... aren't you? ;) 

What Error?
Post code here in a codebox in stead of externally!

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

Oh ok. This is my code:

#include <Includes\ImageSearch\ImageSearch.au3>
While 1
    Local $search = _ImageSearch('find_this.bmp', 0, 0, 0, 0)
    If $search = 1 Then
        MsgBox(0, "", "image found")
    EndIf
    Sleep(500)
WEnd

This is the included ImageSearch.au3:

#include-once
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; 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 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance, $HBMP=0)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP)
EndFunc

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)
Else
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"ptr",$findImage,"ptr",$HBMP)
EndIf

    ; 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

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                    $waitSecs  - seconds to try and find the image
;                   $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 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        sleep(100)
        $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance,$HBMP)
        if $result > 0 Then
            return 1
        EndIf
    WEnd
    return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                    $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                 ARRAY[1] is the first image
;                   $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 the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance,$HBMP=0)
    $waitSecs = $waitSecs * 1000
    $startTime=TimerInit()
    While TimerDiff($startTime) < $waitSecs
        for $i = 1 to $findImage[0]
            sleep(100)
            $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance,$HBMP)
            if $result > 0 Then
                return $i
            EndIf
        Next
    WEnd
    return 0
EndFunc

This is my error message:

scrn11664.png.864ba623c2b0c22be19468dc4f2529d4.png

 

Link to comment
Share on other sites

  • Developers

I can only assume that the DLL isn't found as the DLLCALL doesn't return an Array, so where is the DLL located ?

Jos

EDIT: Did you even look in this thread whether others had this issue?
I see on page 2 of this thread several similar questions and a possible answers.

Edited by 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

  • 2 weeks later...

Hi

I have made some research to speed up the search.

Max Speed is screen frequency 60 search per second or more like 144Hz.

to reach the max speed you can:

-Preload the dll ex.: $dll = DllOpen("ImageSearch.dll")

-Use directly dllcall ex: $res = DllCall($dll, "str", "ImageSearch", "int", $left, "int", $top, "int", $right, "int", $bottom, "str", "*TransFFFFFF *85 picture.gif")

-Reduce the search area

-Reduce Image size

-Use gif

-Use Black and White if possible

-use RAM Disk to Speedup the load of the image and preserve your hard drive

-Make temp folder on your ram disk with ex:

EnvSet("TEMP", "D:\")
EnvSet("TMP", "D:\")

 

 

Edited by voidFF
Link to comment
Share on other sites

  • 5 months later...

Hi all. Long time user, first time poster.

 

I'm having scaling problems with the image finder. So from what I can tell, the image finder works but not what I want it specifically for.

I'm trying to find this image - https://ibb.co/zxPXwLJ

When I search my screens, it doesn't find the image as it is quite small (approximately 70x70 pixels on a 1080x1920 screen. But if I open the Windows folder with the preview of the image it finds it. In Windows folder it will find the image when the view is set to "Large Icons" but can't find it on "Medium Icons".

Is there a way to make the image finder work on a smaller scale like that pixel size or adjust the code to find a match based on pixel size?

Here is my Code:

#include <ImageSearch2015.au3>

$x1=0
$y1=0
$i=0

$picture = "arch.PNG"
While $i<2
   $result = _ImageSearch($picture,0,$x1,$y1,0,0)
;_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency =0)
   If $result=1 Then
      ConsoleWrite("Yes")
      Sleep(900)
      $i=$i+1
   Else
      Sleep(900)
      $i=$i+1
   EndIf
WEnd

 

Link to comment
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
 Share

×
×
  • Create New...