ImageSearch: search on an image file instead of on the screen - is it possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

ImageSearch: search on an image file instead of on the screen - is it possible?

24 Apr 2023, 14:19

Hi.

I was wondering if there was a way to find an image (e.g. in png format) in another, larger image (also in png format).
Is it possible to use ImageSearch for that?

Greets Spitzi
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

24 Apr 2023, 14:49

Yes, as long as the image that you need to find is visible. Try it. See if it works.

When you search for an image, your target is not an image file. It is pixels displayed on the screen.
User avatar
Chunjee
Posts: 1500
Joined: 18 Apr 2014, 19:05
Contact:

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

24 Apr 2023, 15:56

Spitzi wrote:
24 Apr 2023, 14:19
Hi.

I was wondering if there was a way to find an image (e.g. in png format) in another, larger image (also in png format).
Is it possible to use ImageSearch for that?

Greets Spitzi
Possible, yes
Realistic, no

Greets Spitzi
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

24 Apr 2023, 15:58

I guess I misunderstood, thought that the image was being displayed-- oops, didn't read the subject carefully enough!
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

25 Apr 2023, 00:01

My image scan class is capable of this, you can find the github here > https://github.com/Spawnova/ShinsImageScanClass

here is an example on how it is used

Code: Select all

#include ShinsImageScanClass.ahk

scan := new ShinsImageScanClass() ;only create this once at the top

scan.SetTargetImageFile("LargeImageToSearch.png") ;sets the target to be a local image file instead of the desktop or target window

msgbox % scan.Pixel(0xFF0000,0,x,y) "`n" x "," y  ;scans for a red pixel and returns the x,y
msgbox % scan.Image("smallerImage.png",0,x,y) "`n" x "," y ;scans for an image and returns the x,y

exitapp
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

26 Apr 2023, 01:32

Hi @Spawnova.

Love it! This looks very promising and should be exactly what I want. I'll give you feedback in a few days.

Greets Simon
Spitzi
Posts: 315
Joined: 24 Feb 2022, 03:45

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

26 Apr 2023, 03:06

Hi again @Spawnova.

Your code works nicely and is indeed a little bit faster than ImageSearch: on a dual 4k monitor setup I searched the desktop for a small image in the far right lower corner of the screen, it took about 250ms. With ImageSearch about 350ms.

Then I tried it using only a program window - turns out that it was slower than, about 450ms. Why is that?
And is it possible to have an array of all occurrences of the image on the screen?

Thanks again. Spitzi
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: ImageSearch: search on an image file instead of on the screen - is it possible?

26 Apr 2023, 03:44

Window scanning should be significantly faster than desktop, though it may not work on some directx games
you can easily get all matches by using the ImageArray function, here is an example

Code: Select all

#include ShinsImageScanClass.ahk

scan := new ShinsImageScanClass("WindowTitleHere")

return

f1::
;region scans will be faster than normal ones, image array is the slowest scan overall though
;scans for all images in the region of 0,0 to 500,500 with 0 variance
;the results are stored in the results array which contains the x,y
if (scan.ImageArrayRegion("image.png",results,0,0,500,500)) {   
	for k,v in results
	{
		msgbox % "Match " a_index ": " v.x "," v.y
	}
} else {
	msgbox % "Could not find any matches for image.png"
}
return
if there is any other issues you can also message me on discord @ Spawnova#2957, I check it a few times a day =P

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 335 guests