_imageSearchArea Help

04/01/2014 20:46 turtlebeach#1
Hello again all. I've found the autoIt Help file is amazing at answering questions, however I have not been able to find any documentation there for _ImageSearchArea. My google results have been just as unsuccessful so I'm hoping someone can help me understand how it works by providing a couple of concrete examples.

So, would someone be able to show me a couple of examples, such as

1) If my desktop is 1024 x 768 and I want to search only the top half of the desktop area for an image called blue_btn.png, what would that look like.

2) If my desktop is 1024 x 768 and I want to search only the left half of the desktop area for an image called blue_btn.png, what would that look like.

3), lastly, if my desktop is 1024 x 768, and I want to constrain the search to a box that is centered and is 800 wide by 400 tall (for the same image as above).
04/01/2014 22:19 butter123#2
in the imagesearch.au3 are explanations for the function.
just enter the coordinates of the area you want to search.
04/02/2014 02:02 Paraly#3
Just call the function which you need.

Code:
Func _Top_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth,@DesktopHeight * 0.5,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Top_half()
	EndIf
EndFunc


Func _Left_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth * 0.5,@DesktopHeight,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Left_half()
	EndIf
EndFunc


Func _Centered()
	$X = 0
	$Y = 0
	$centerX = @DesktopWidth * 0.5
	$centerY = @DesktopHeight * 0.5
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,$centerX -400, $centerY -200, $centerX +400,$centerY +200,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Centered()
	EndIf
EndFunc
04/02/2014 03:03 turtlebeach#4
that helps, is @DesktopWidth an automagically stored variable or is this a real number, ie would I need to put "1024" in wherever you have @DesktopWidth ?
04/02/2014 03:29 Paraly#5
Quote:
Originally Posted by turtlebeach View Post
that helps, is @DesktopWidth an automagically stored variable or is this a real number, ie would I need to put "1024" in wherever you have @DesktopWidth ?
@DesktopWidht and @DesktopHeight are macros which contains automatically your current desktop resolution :)
04/02/2014 05:08 turtlebeach#6
Got it, thanks, that helped a ton. This is the best explanation of _ImageSearchArea on the net. My script is so much faster now and I'm only partially done with it :)
04/02/2014 16:21 alpines#7
Recursion error missle launched - Impact in 2000 calls.
Quote:
Originally Posted by Paraly View Post
Just call the function which you need.

Code:
Func _Top_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth,@DesktopHeight * 0.5,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Top_half()
	EndIf
EndFunc


Func _Left_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth * 0.5,@DesktopHeight,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Left_half()
	EndIf
EndFunc


Func _Centered()
	$X = 0
	$Y = 0
	$centerX = @DesktopWidth * 0.5
	$centerY = @DesktopHeight * 0.5
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,$centerX -400, $centerY -200, $centerX +400,$centerY +200,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Centered()
	EndIf
EndFunc
04/04/2014 17:33 FacePalmMan#8
Quote:
Originally Posted by Paraly View Post
Just call the function which you need.

Code:
Func _Top_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth,@DesktopHeight * 0.5,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Top_half()
	EndIf
EndFunc


Func _Left_half()
	$X = 0
	$Y = 0
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth * 0.5,@DesktopHeight,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Left_half()
	EndIf
EndFunc


Func _Centered()
	$X = 0
	$Y = 0
	$centerX = @DesktopWidth * 0.5
	$centerY = @DesktopHeight * 0.5
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,$centerX -400, $centerY -200, $centerX +400,$centerY +200,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
	Else
		_Centered()
	EndIf
EndFunc
Just at looking at it i can see that every single function would produce an stack overflow error.
calling the function over and over again will only fill the stack until it its full.
and after taking a closer look at it i see that you put the value 0 in the variables x and y, and never change it. that means when it finds the image, it moves the mouse to position 0,0 on the screen.
04/04/2014 19:04 Paraly#9
Quote:
Originally Posted by FacePalmMan View Post
Just at looking at it i can see that every single function would produce an stack overflow error.
calling the function over and over again will only fill the stack until it its full.
and after taking a closer look at it i see that you put the value 0 in the variables x and y, and never change it. that means when it finds the image, it moves the mouse to position 0,0 on the screen.
god.. this was just a explaination how _imagesearcharea works, what arguments are needed, he understand it so gtfo

Here is the code for people who only got the ability to copy paste without using their brain
Code:
#include <ImageSearch.au3>
Global $found = False, $X, $Y

;Search for the Pic at the Top half until its found;
Do
$found = _Top_half()
 sleep(25)
Until $found = True
$found = False

;Search for the Pic at the Left half until its found;
Do
$found = _Left_half()
 sleep(25)
Until $found = True
$found = False

;Search for the Pic at the Center until its found;
Do
$found = _Centered()
 sleep(25)
Until $found = True
$found = False
Exit



Func _Top_half()
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth,@DesktopHeight * 0.5,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
		Return True
	Else
		Return False
	EndIf
EndFunc


Func _Left_half()
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,0,0,@DesktopWidth * 0.5,@DesktopHeight,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
		Return True
	Else
		Return False
	EndIf
EndFunc


Func _Centered()
	$centerX = @DesktopWidth * 0.5
	$centerY = @DesktopHeight * 0.5
	$bResult = _ImageSearchArea(@ScriptDir & "\blue_btn.png",1,$centerX -400, $centerY -200, $centerX +400,$centerY +200,$X, $Y, 0)
	If $bResult = 1 Then
		MouseClick("LEFT",$X, $Y)
		Return True
	Else
		Return False
	EndIf
EndFunc
04/04/2014 22:43 FacePalmMan#10
Quote:
Originally Posted by Paraly View Post
god.. this was just a explaination how _imagesearcharea works, what arguments are needed, he understand it so gtfo
jeese. i only pointed out a mistake you did (one that i until some weeks ago didnt even know about that it exists). im sorry but thats no reason to say "gtfo".
04/06/2014 21:01 turtlebeach#11
Well I don't know about all that jive trying to use a function to find it, seems to overcomplicate the matter. I just used the method to locate the center and then went from there, ie:

Code:
;Press accept function ----------------------------------------------------------
Func pressAccept()
    Local $result = _ImageSearchArea("pics/login/accept_btn.png", 1, $centerX -150, $centerY -70, $centerX +150,$centerY +70,$x, $y, $tol)
    If ($result == 1) Then
        MouseClick("left", $x, $y, 1)
    EndIf
EndFunc  
;Press accept function ----------------------------------------------------------