AutoHotkey Community

It is currently May 27th, 2012, 9:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: ImageSearch basics
PostPosted: November 12th, 2011, 1:30 pm 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
I can't seem to get a very simple ImageSearch script working for me.
Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, Pixel, Relative  ; Interprets the coordinates below as relative to the screen rather than the active window.

ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, NTlogo.bmp
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Image could not be found on the screen.
else
    MsgBox The icon was found at %FoundX%x%FoundY%.


I have taken a screenshot of a logo and saved it to a .bmp, then I load the bmp in Windows Photo Viewer so that it is visible on the screen. When I run the script, I get the ErrorLevel 1.

I have tried adding more shades of variation with the same result. :?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 2:23 pm 
My script similiar to yours differs in that;
May or may not be of some help.

Code:
ImageSearch, FoundX, FoundY, 10,10, 1000, 1000, ifactive.bmp ; My Images\test.bmp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 2:46 pm 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
LarryC wrote:
My script similiar to yours differs in that;
May or may not be of some help.

Code:
ImageSearch, FoundX, FoundY, 10,10, 1000, 1000, ifactive.bmp ; My Images\test.bmp


The difference I see is in your use of absolute coordinates, I've tried that too without success. :?

I have a multiple monitor setup, but I don't think that should be causing an issue. . .


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 3:41 pm 
Well your code did not indicate such, only showed you using empty variables.
Another problem I had was using the Help files directions to capture the bmp, using Paint.
When changed to "FastStone Capture" instead of Paint and this exact same script immediately found the BMP. Hope that helps.
Let us know.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 3:55 pm 
Offline
User avatar

Joined: December 5th, 2010, 7:19 pm
Posts: 311
NVM POST.

_________________
Image


Last edited by gamax92 on November 12th, 2011, 4:19 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 4:01 pm 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
LarryC wrote:
Well your code did not indicate such, only showed you using empty variables.
Another problem I had was using the Help files directions to capture the bmp, using Paint.
When changed to "FastStone Capture" instead of Paint and this exact same script immediately found the BMP. Hope that helps.
Let us know.

Hmmm, the screenshot was take with FastStone Capture.

I also just tried
Code:
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79

ImageSearch, FoundX, FoundY, 0, 0, VirtualWidth, VirtualHeight, NTlogo.bmp
. . .

Still not finding the image.

I don't imagine that the image itself could be an issue (is there a size limitation?), but I've posted it here: http://localhostr.com/download/6z276q2/ntlogo.bmp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 4:13 pm 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
gamax92 wrote:
Your using function syntax in something thats not a function.
When not in function. All variables being read and not set need percent signs around them.

Thanks, I am using the syntax per the help file example.

At your suggestion, I did try it with the percent signs too, still no luck.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 6:11 pm 
Offline

Joined: May 20th, 2009, 6:18 pm
Posts: 129
Quote:
.... I am using the syntax per the help file example.


It is mystifying. I hadn't had too much trouble with imagesearch in the past, but when I tried your script, which is the example in the help file, it didn't seem to work. I think maybe what's the problem is, not the program with which one captures the image file, but displaying the image in Windows Photo Viewer. I'm not sure, because I don't have enough time to continue trying examples, but in working on this problem I found the same problem with Windows Picture and Fax Viewer, which the image files display in automatically if I double-click on them. But when the image was on the screen some other way, then the script seemed to work (I modified it to run according to a hotkey and to have coordinates relative to the screen). What I did was take a screenshot of something else on the screen, and use imagesearch to see if it would match the resulting file to the screen. That worked. Except that if I took a screenshot of the image as it appear in Windows Picture and Fax Viewer, I couldn't get it to match the image in Windows Picture and Fax Viewer.

Oh, I forgot to mention that I added a "*55" parameter to imagesearch to allow for a slight variation in color in between the file and the image.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 6:43 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
Try this script. It loads the image into a gui and then F1 searches for the image.

Code:
; change to the name of your image, in the same folder as this script

image_name=NTlogo.bmp



#singleinstance force

; if you change the value after 'if' to 1, all coordinates will be relative to screen/monitor
; if you leave the value at 0, all coordinates will be relative to current window

if 1   ; screen coordinates
  coord=screen
else
  coord=relative
tooltip, %coord%   ; remind user of the mode
sleep, 1000

tooltip,       ; hide the reminder

CoordMode, ToolTip, %coord%
CoordMode, Pixel, %coord%
CoordMode, Mouse, %coord%
CoordMode, Caret, %coord%
CoordMode, Menu, %coord%


; this two lines creates a window that has the image in it, for practice; this is temporary

gui, add, picture, , %image_name%
gui, show, , mywindow


SetTimer, WatchCursor, 100
return

; this shows the current location of the mouse,
;   you can use this information to edit the search location

WatchCursor:
MouseGetPos,xpos , ypos , id, control
ToolTip, xpos: %xpos%`nypos: %ypos%,,, 2

return


; search for the image, it must be completely visible

f1::

ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %image_name%

if ErrorLevel = 2
    tooltip Could not conduct the search.
else if ErrorLevel = 1
    tooltip Image could not be found on the screen.
else
{
    mousemove, %FoundX%, %FoundY%, 10
    tooltip The image was found at %FoundX%x%FoundY%.

}
return

esc::
   msgbox script closed by user
exitapp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 7:31 pm 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
Leef_me wrote:
Try this script. It loads the image into a gui and then F1 searches for the image.


The script runs fine and the image is visible in the GUI, however when I press F1 I get the "Image could not be found on the screen" tooltip.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 11:14 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
>>I have a multiple monitor setup, but I don't think that should be causing an issue. . .

How many screens do you have?
If you have more than one screen, is the gui within the screen which has coordinates of the imagesearch?

I use 24bit bmp and my searches usually work fine.
What resolution of screen are you using?
I see you are using 8 bit for the image
Can you capture and save the image as the same resolution as your screen?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2011, 2:05 am 
Offline

Joined: February 23rd, 2008, 6:52 pm
Posts: 30
BINGO! mostly. . .

Quote:
I use 24bit bmp and my searches usually work fine.

That seems to have been most of the issue. I resaved at 24bit and I can now find the image by using WinGetPos to narrow the search area.

As a point of interest, I have a less usual multimonitor setup that seems to cause a quirk.

My setup looks like this
Image

When I use
Code:
SysGet, VirtualWidth, 78
SysGet, VirtualHeight, 79

to search the entire desktop, the image will be found unless it is on Monitor 3 below the lower edge of the other monitors.
Of course, this happens to be exactly where I need to find the image.
As I said though, it does work if I specify the search area by getting coordinates from the active window first; so from a practical standpoint, issue solved.

Thank you all for your help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2011, 3:59 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
I too have a non-starndard arrangement
Image

Please look at the "sub-commands" section and at example #2
http://www.autohotkey.com/docs/commands/SysGet.htm
You can disect the example and find the coordinates information that you need.


OTOH, are you perhaps trying to get information about an icon in the system tray?
If so, read on...
One of the first, if not THE first script I wrote checks my mail icon for me.
I happen to >hate< windows computer sounds: beeps, clicks, whatever; so I turn sounds off.
I use settimer with this code.
Code:
Alert1:
msg:=TrayIcons("wlmail.exe")

if msg contains You have new e-mail
{
; insert your chosen message here
}
return

#include TrayIcon.ahk
; Extract Informations about TrayIcons
; http://www.autohotkey.com/forum/topic17314.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2011, 4:44 pm 
Offline

Joined: November 8th, 2011, 12:54 am
Posts: 31
Location: United States
I know this is a dead post but it shows up on a google search for imagesearch so I wanted to add a little bit more helpful information.

I found that it takes a *125 in order for an image to be able to be recognized as displayed in the windows picture and fax viewer.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, hyper_, tomoe_uehara, Yahoo [Bot] and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group