Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Question for Imagesearch expert

  • Please log in to reply
2 replies to this topic
  • Members
  • 68 posts
  • Last active: Aug 14 2016 07:53 PM
  • Joined: 28 Oct 2012
Does Imagesearch stop searching as soon as it finds a match in the search region, or does it find a match, but keeps searching the remainder of the search field? It seems to me that to keep on searching after a successfully search, is a waste of resources. Also it would be much, much easier to program for a search simply using; "ImageSearch, OutputVarX, OutputVarY, X1, Y1, A_ScreenWidth, A_ScreenHeight,ImageFile" instead of; "ImageSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ImageFile" In Help it says "Since the search starts at the top row of the region and moves downward, if there is more than one match, the one closest to the top will be found." seems to indicate searching continues, but will not do anything even if it finds more, ?so that does not answer my question

  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

My understanding is it does not keep searching after a match. Yeah, the documentation isn't very clear. Maybe it'd be better worded "If there are multiple areas on the screen that could be a match, only the first one is found and the search ends." I believe it to only search until one match because otherwise the command might have natively supported reporting back multiple matches. (Though I get the logistics of that might be tricky cause it might report hundreds of matches in the same little area due to variation tolerances; if you were to omit any matches that overlap a previously identified match, then people who wanted overlaps would complain about that.)


BTW, you are free to use A_ScreenWidth and A_ScreenHeight just as you used them above for the X2 and Y2 coordinates if you'd like.

  • Members
  • 14 posts
  • Last active: Nov 13 2015 10:03 AM
  • Joined: 03 Feb 2010

Yes, it only finds the 1st one, or at least it only returns the first image found.


If you want the second one you can find the first one, then do a second search, starting 1 pixel after (on the x-axis) you fist result which will find the next one.


If you want the 2nd last one, you will have to count the number of images with a counter increasing for each found image. Then take you total number, subtract one to get the nth image and search that many times.  




Interesting, I did a test looking for a image that should be found faster (top left) of the screen and timed that (93ms best time)  then did a search for something at the bottom right and the best time I got was faster (78ms best time).  The average times were longer for the second one but maybe my use of "A_TickCount" was not correct.  Might also be something to do with the detail in the images that I was looking for.  I just used a bit of code I had from a last project.