Image Search not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Image Search not working

Post by gignu » 09 Jul 2019, 05:32

I was reading about image search for hours and I just can't figure out why it's not working :headwall:
Does anyone have an idea what might be the problem?`

Code: Select all

F1 & i::
	ImageSearch, FoundX, FoundY, 0, 0, 1365, 767, C:\Users\Admin\Desktop\Caballo.png

	if ErrorLevel = 2
		MsgBox Could not conduct the search.
	else if ErrorLevel = 1
		MsgBox Icon could not be found on the screen.
	else
		MsgBox The icon was found at %FoundX%x%FoundY%.
	return

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Image Search not working

Post by Helgef » 09 Jul 2019, 06:30

What is the value of ErrorLevel? A common error is not setting CoordMode appropriately,
ImageSearch wrote: Coordinates are relative to the active window unless CoordMode was used to change that.
Cheers.

gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Re: Image Search not working

Post by gignu » 09 Jul 2019, 12:25

The value of ErrorLevel is 2

gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Re: Image Search not working

Post by gignu » 09 Jul 2019, 12:35

Now I converted the image to bmp and now I get ErrorLevel 1

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Image Search not working

Post by Helgef » 09 Jul 2019, 12:40

You need to use a lossless (perfect) image or try the *n option as described in the documentation.

gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Re: Image Search not working

Post by gignu » 09 Jul 2019, 13:29

I thought that bmp and png were lossless but it still doesn't work ;(

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Image Search not working

Post by gregster » 09 Jul 2019, 13:38

Did you make sure about the correct setting of Coordmode, like Helgef suggested?

Also, consider this:
https://www.autohotkey.com/docs/commands/ImageSearch.htm#Remarks wrote:A strategy that is sometimes useful is to search for a small clipping from an image rather than the entire image. This can improve reliability in cases where the image as a whole varies, but certain parts within it are always the same. One way to extract a clipping is to:

1. Press Alt+PrintScreen while the image is visible in the active window. This places a screenshot on the clipboard.
[...]

gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Re: Image Search not working

Post by gignu » 09 Jul 2019, 14:14

I've made a few changes to my original script, including *n and Coordmode:

Code: Select all

F1 & i::
	CoordMode, Pixel
	ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *n C:\Users\Admin\Desktop\soccer.bmp
	if ErrorLevel = 2
		MsgBox Could not conduct the search.
	else if ErrorLevel = 1
		MsgBox Icon could not be found on the screen.
	else
		MsgBox The icon was found at %FoundX%x%FoundY%.
	return	
I saved the image as 24-bit bitmap (bmp) to my desktop.
So what I do is, go to my desktop press F1 & i and I get ErrorLevel 1

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Image Search not working

Post by Helgef » 09 Jul 2019, 14:26

The n in *n should be an integer, for example *2.

Cheers.

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: Image Search not working  Topic is solved

Post by boiler » 09 Jul 2019, 15:27

gignu wrote:
09 Jul 2019, 12:35
Now I converted the image to bmp and now I get ErrorLevel 1
Is your image captured directly from the source as a bmp or did you convert it from some other format? If you converted to bmp from a lossy format, it doesn't eliminate the losses. It needs to be a bmp or a png from its creation.

gignu
Posts: 30
Joined: 14 Jun 2019, 09:00

Re: Image Search not working

Post by gignu » 10 Jul 2019, 09:30

It works!!!
@boiler That was a good hint :D I used the Winows Snipping Tool and that did the trick!
Thank you all for your help :bravo:

sameclarke
Posts: 5
Joined: 21 Nov 2020, 12:52

Re: Image Search not working

Post by sameclarke » 18 Dec 2020, 05:39

Hi had a similar problems on google photos website, image search worked Ok on laptop but not on PC (both windows 10). As suggested I used Snip and Sketch to take png snapshot of the button ("Create album" on https photos.google.com /albums Broken Link for safety page) and it worked OK when using the snapshot.

Could this be a problem a problem with screen resolution I am using 2560 x 1440 on PC and 1366 x 768 on laptop

Sam Clarke

User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: Image Search not working

Post by boiler » 18 Dec 2020, 09:51

The resolution difference itself is most likely not the issue unless google photos itself is scaling the images differently based on the size of the window it’s being displayed in. Another potential and related issue is if your Windows scaling setting is different on either computer, especially if it’s set at 150% scaling or higher. In those cases, Windows stretches images and blends the colors across the new number of pixels when it displays them, so the image can’t be found from the reference image.

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Image Search not working

Post by SOTE » 19 Dec 2020, 02:22

sameclarke wrote:
18 Dec 2020, 05:39
Hi had a similar problems on google photos website, image search worked Ok on laptop but not on PC (both windows 10). As suggested I used Snip and Sketch to take png snapshot of the button ("Create album" on https photos.google.com /albums Broken Link for safety page) and it worked OK when using the snapshot.

Could this be a problem a problem with screen resolution I am using 2560 x 1440 on PC and 1366 x 768 on laptop

Sam Clarke
1) You might want to see if using jpg or gif works better than png. This is because png has different formats, and what device or application is supporting what, can get weird. Oddly, switching file type works better sometimes, not sure why.

2) You could also create alternative copies of your picture at higher resolutions or different scaling and put it in the folder. So if picture1.jpg is not found, then it searches for picture2.jpg, etc...

3) I noticed that some people get too tight with *n (variation). Between computers, you might want to try to loosen up the number. Instead of *2, try *20, *80, etc... The key is try a number high enough where the picture gets recognized accurately, but not too high where it recognizes everything and the results are trash. Sometimes the trick is that a good number is something like *75 and it works.

Just some suggestions.

Post Reply

Return to “Ask for Help (v1)”