Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ImageSearch basics


  • Please log in to reply
14 replies to this topic
drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008
I can't seem to get a very simple ImageSearch script working for me.
#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. :?

LarryC
  • Guests
  • Last active:
  • Joined: --
My script similiar to yours differs in that;
May or may not be of some help.

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


drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008

My script similiar to yours differs in that;
May or may not be of some help.

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. . .

LarryC
  • Guests
  • Last active:
  • Joined: --
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.

gamax92
  • Members
  • 411 posts
  • Last active: Aug 06 2013 05:00 AM
  • Joined: 05 Dec 2010
NVM POST.

drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008

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
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: <!-- m -->http://localhostr.co...76q2/ntlogo.bmp<!-- m -->

drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008

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.

comvox
  • Members
  • 143 posts
  • Last active: Jan 29 2017 06:53 AM
  • Joined: 20 May 2009

.... 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.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Try this script. It loads the image into a gui and then F1 searches for the image.

; 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


drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008

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.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
>>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?

drmartell
  • Members
  • 35 posts
  • Last active: Nov 05 2015 08:18 PM
  • Joined: 23 Feb 2008
BINGO! mostly. . .

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
Posted Image

When I use
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.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
I too have a non-starndard arrangement
Posted Image

Please look at the "sub-commands" section and at example #2
<!-- m -->http://www.autohotke...ands/SysGet.htm<!-- m -->
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.
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


scantron
  • Members
  • 40 posts
  • Last active: Dec 08 2015 05:11 PM
  • Joined: 07 Nov 2011
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.

bobmob
  • Members
  • 1 posts
  • Last active: Aug 20 2013 01:14 PM
  • Joined: 14 Aug 2013

I have tried this it works fine on my desk top, but I want to use it on a Netbook running Windows & starter and an old Laptop running XP.  It does work on either. 

 

It fails to find the image. 

 

I have tried increasing the variation field, but it does not help.