Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

ImageSearch


  • Please log in to reply
11 replies to this topic
Jessie
  • Guests
  • Last active:
  • Joined: --
Erm, my question is how do you image search for a image in your folder?


I mean like:

ImageSearch.ahk (is in folder A)
image.bmp (is in folder A)

when I do:
ImageSearch, FoundX, FoundY, 0,0, 2000, 2000, inventory.bmp

it gives me ErrorLevel2 which means it can't find the image location...

any help?

Josh
  • Guests
  • Last active:
  • Joined: --
Try adding a / before the image file.

Jessie
  • Guests
  • Last active:
  • Joined: --
Nice guess! But no... didn't work.. Any more suggestions?

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
If the script and the image are both in the same directory, what you have posted should work... But, try providing an absolute path for the image file (e.g. C:\Documents\Whatever\inventory.bmp)

VxE
  • Moderators
  • 3622 posts
  • Last active: Oct 24 2013 04:25 AM
  • Joined: 07 Oct 2006
I'm guessing that theproblem is in the region specified for the image search. You should try
Coordmode, pixel, screen
ImageSearch, FoundX, FoundY, 0,0, %A_ScreenWidth%, %A_ScreenHeight%, image.bmp

To answer your other question:
You can either specify an absolute path to the image.
ipath = %A_MyDocuments%\Ahk Macros\image.bmp
;...
ImageSearch, FoundX, FoundY, 0,0, %A_ScreenWidth%, %A_ScreenHeight%, %ipath%

or you can set the working directory to the folder that has the image
SetWorkingDir, %A_MyDocuments%\Ahk Macros\
;...
ImageSearch, FoundX, FoundY, 0,0, %A_ScreenWidth%, %A_ScreenHeight%, image.bmp

or you can search a folder and subfolders for an image with a matching name
Loop, %A_MyDocuments%\image.bmp, 0, 1
   ipath = %A_LoopFileLongPath%
;...
ImageSearch, FoundX, FoundY, 0,0, %A_ScreenWidth%, %A_ScreenHeight%, %ipath%

And, no matter which way you choose, using
IfNotExist %YourImageFilePathAndName%
   MsgBox Dur! script es muy stupido`nFile not found.
should at least tell you if the script can find the file.

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008

it gives me ErrorLevel2 which means it can't find the image location...

I'm guessing that theproblem is in the region specified for the image search.


Read the poster a little more carefully, [VxE] :p Even if you didn't know the ErrorLevel 2 means the script can't open the image file, he says it right there. Silly boy.

VxE
  • Moderators
  • 3622 posts
  • Last active: Oct 24 2013 04:25 AM
  • Joined: 07 Oct 2006

ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).

Errorlevel 2 could mean several things. But it's true that I don't have much experience with imagesearch :p

silkcom-offline
  • Guests
  • Last active:
  • Joined: --
Is it just me or is image.bmp not equal to inventory.bmp. I assume that this isn't the mistake, but it's obvious which usually is right :).

I've used image search a lot with relative addressing without any problems.

skyd1v3r
  • Members
  • 73 posts
  • Last active: Apr 18 2010 11:42 AM
  • Joined: 18 Jun 2009
Another question on imagesearch:

Let´s say I want to search an image of 100*100.
I have found that the upper left corner is at 600/600.

Can I specify the coordinates to search with 599,599,601,601?
Or do I need to use 599,599,701,701?

With other words, does the complete image need to be withhon the parameters, or only the upper left corner?

Choosing tight coorinates is a matter of performance withhin loops...

Thanks

silkcom
  • Members
  • 162 posts
  • Last active: Apr 13 2010 08:12 PM
  • Joined: 23 Jan 2008
I believe you would need 599,599,701,701 but i haven't verified it. Though it should be pretty easy to check.

Zeleene
  • Members
  • 15 posts
  • Last active: Oct 26 2011 02:08 PM
  • Joined: 23 Jun 2011
skyd1v3r:

This shouldnt matter. If you put 600,600,10000000,10000000
the 2nd number shouldnt matter since the first thing the ImageSearch does is find the picture @ 600,600

So even if you want to do it 599,599,601,601 (if this doesnt work) you could just aswell do 600,600,A_ScreenWidth,A_ScreenHight

I have not verified this but its the most logical result.

Leef_me
  • Moderators
  • 8125 posts
  • Last active: Today, 12:39 PM
  • Joined: 08 Apr 2009
Hi Zeleene, welcome to the forum.

Thanks for trying to help others. :)

But I'll point out the following things:

1. The thread is almost 24 months old
2. the user you responded to has not posted in over 20 months.
3. you gave an answer that you didn't test
4. you gave an answer that doesn't address the question
5. you gave an "the 2nd number shouldnt matter" which is wrong
(you probably meant "the 2nd corner", and you are still wrong)

With other words, does the complete image need to be withhon the parameters, or only the upper left corner?

6. The proper answer is Yes, the complete image must be within the search area

Choosing tight coorinates is a matter of performance withhin loops...

7. Finding an image using coordinates of 600,600,10000000,701 will take longer to search than 600,600,701,701