Sign in to follow this  
Followers 0
jiut

[Help] _ImageSearch - Search inside a window and multiple image search

10 posts in this topic

Hi,

I am trying to do the following:

Search for an image inside a window (right now I can only search the entire desktop), and if it's found, do action 1.

Else If, search image 2, and if it's found, do action 2.

Else, do nothing.

Run the code every 60 minutes.

So far I have the following code:

#include <ImageSearch.au3>

$x1=0
$y1=0

$weaknessBar = _ImageSearch("C:\AutoIt\image1.bmp",1,$x1,$y1,0)
$strengthBar = _ImageSearch("C:\AutoIt\image2.bmp",1,$x1,$y1,0)

If $weaknessBar = 1 Then
MsgBox(0,"1","found image1")
ElseIf $strengthBar = 1 Then
MsgBox(0,"2","found image2")
Else
Sleep(3600000)
EndIf

The problem with this is that it searches the whole desktop and not inside a specific window.

I'm not sure if it's possible to search inside a window, but I couldn't implement _ImageSearchArea, either =/

Plus, how can I search multiple images? If I remove one of those variables the script runs fine, but I keep them both I get the following error:

C:\Program Files (x86)\AutoIt3\Include\ImageSearch.au3 (49) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Any help is much appreciated! Thank you very much

Share this post


Link to post
Share on other sites



I've tried using 'window info', but the values I'm looking for don't show up. That'd be the best option, making it a lot simpler..

That's why I'm trying to use image recognition, which works for the purpose, but I don't know how to look for several images.

Is there some reason why you don't try to interact with the controls on the screen by getting an ID of the controls?

Share this post


Link to post
Share on other sites

ElseIf should also work..

I've tried your solution and if image1 shows up, it works.

However, if image2 appears it shows the same error as before :/

You have multiple if statments.

$image1 = _Imagesearch(blah)
if $image1 = 1 then
MsgBox(0, "Found", "Found")
else
MsgBox(0, "Error", "Not found")
Endif

$image2 = _Imagesearch(blah)
if $image2 = 1 then
MsgBox(0, "Found", "Found")
else
MsgBox(0, "Error", "Not found")
endif

Share this post


Link to post
Share on other sites

@John - ?

@Juit - Its hard to know what your tryign to do but maybe this will help i used imagesearcharea though.

#include <ImageSearch.au3>

Global $x = 0
Global $y = 0
;I set the desktopheight/width becuase @desktopheight/width didnt work correctly.

Global $DesktopHeight = 1280
Global $DesktopWidth = 1025 

sleep(5000) ;sleep so i could goto my image directory
$image1 = _ImageSearchArea("test1.png", 1, 0, 0, $DesktopHeight, $DesktopWidth, $x, $y, 100)
If $image1 = 1 then
MsgBox(0, "Found", "Found")
sleep(1000) ;just a second delay increase remove OR use a while 1 statment to search for them image repeatedly.
$image2 = _ImageSearchArea("test1.png", 1, 0, 0, $DesktopHeight, $DesktopWidth, $x, $y, 100)
If $image2 = 1 Then
MsgBox(0, "Found", "Found")
Else
MsgBox(0, "Error", "Error")
EndIf
Else
MsgBox(0, "Error", "Error")
EndIf

Share this post


Link to post
Share on other sites

Thank you, Gotemp.

I suspect there's something wrong with my ImageSearch.au3 file.

The first image verification always work, but if the first image (for verification) isn't present the script always crashes with:

ImageSearch.au3 (49) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Also, is it possible to search a specific area in a window, by inputting the upper left and bottom right relative coordinates?

Thank you

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Juit for searching a certain area you would use ImageSearchArea which im using in the code above, i always search the whole screen though incase there is a mis-happ like the image in the wrong place, wrong screen resolution etc etc so i think its the smarter way to code not to mention it takes added to to get the cords.

If you did want to specify an area then change the 0, 0, $desktopheight, $desktopwidth to the areas you want 0 = left, 0 = top, Height = right, width = bottom (maybe i'll rename them lol) as for your imagesearch.au3 click my name and check my posts one has a copy of the one im using.

Edited by Gotemp

Share this post


Link to post
Share on other sites

It's working great Gotemp, thank you very much!

The problem was indeed in ImageSearch.au3. I copied the one you posted on another thread.

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
Sign in to follow this  
Followers 0