Gdip_ImageSearch, i am unable to find all instances Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Gdip_ImageSearch, i am unable to find all instances

04 Dec 2017, 00:48

Hello,
i am new to this forum, please do excuse me for any mistakes.

Gdip_ImageSearch, i am trying to find a image count and position, unable to find all instances, please help.

thanks in advance.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Persistent
#SingleInstance force
SetTitleMatchMode, Slow
SetTitleMatchMode, 2
SetBatchLines, -1

CoordMode Pixel, Screen
;~ #Include *i Gdip_All.ahk
#Include *i Gdip_ImageSearch.ahk

CapsLock::
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
l := ""
pneedle :=Gdip_CreateBitmapFromFile("1.PNG")
Gdip_GetImageDimensions(pneedle , wn, hn)
phaystack:=pBitmap :=bmpHaystack := Gdip_BitmapFromScreen()
;~ phaystack:=pBitmap :=bmpHaystack := Gdip_CreateBitmapFromFile("All.PNG")
Gdip_GetImageDimensions(phaystack , wh, hh)
pGraphics:=Gdip_GraphicsFromImage(phaystack)

pBrush:=Gdip_BrushCreateSolid(0xff000000)

t:=a_tickcount

loop, 10 ;just to be safe
{
    Gdip_ImageSearch(phaystack ,pneedle,list,0,0,wh,hh,10,0x000000,1,0)	; also tried Trans 0xFFFFFF
    
    if !regexmatch(list,"\d")
      break
    l .=list "`n"
    pos:=strsplit(list,",")
}
msgbox % "time= " a_tickcount-t "ms`n" l

Gdip_DisposeImage(phaystack)
Gdip_DisposeImage(pneedle)
Gdip_Shutdown(pToken)
return
All1.png
All1.png (74.95 KiB) Viewed 1571 times
1.PNG
1.PNG (1.26 KiB) Viewed 1898 times
result.PNG
result.PNG (10.94 KiB) Viewed 1898 times
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: Gdip_ImageSearch, i am unable to find all instances

04 Dec 2017, 00:50

Running on Win7 32bit 7600 build, Ahk version 1.1.26.01, U-32bit.
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Gdip_ImageSearch, i am unable to find all instances

04 Dec 2017, 02:41

Image

If text is not included in needle it seems to find all five images .
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: Gdip_ImageSearch, i am unable to find all instances

06 Dec 2017, 03:57

Thanks noname you (few other tech guys) always been great help for guys like me.

you did any modifications to the code or its the same code, because i'm not getting any thing with text removed with pure color FD7E00.

i tried many configurations with variations, i don't know what i'm doing wrong.
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Gdip_ImageSearch, i am unable to find all instances  Topic is solved

06 Dec 2017, 08:37

It is quite tricky to choose the needle ,if you transcolor on the haystack png you can see they are all different:

screenshot : https://i.imgur.com/cPiFCxl.png

Code: Select all

phaystack:=Gdip_CreateBitmapFromFile("haystack.png")
msgbox % Gdip_SetBitmapTransColor(phaystack,0xfd7e00)
Gdip_SaveBitmapToFile(phaystack, "color.png")
You can use a pure color needle by adjusting its width/height so it is within the black parts you can see in the transcolor image of the needle.
But i guess when you look at the browser window they should be equal ?

Here is the code using a pure color needle ( created in the code ), you need to add the libraries you need,i have them in my standard lib so i have no need to include them.
I tested your code with the posted one only removed the loop ( i must have been lucky in choosing the needle for it to work.... :) )
Image

Code: Select all

SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1


If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

pneedle :=Gdip_CreateBitmap(16,13)
g:=Gdip_GraphicsFromImage(pneedle)  ; create needle with pure color
Gdip_GraphicsClear(g,0xfffd7e00)

Gdip_GetImageDimensions(pneedle , wn, hn)

;phaystack:=Gdip_CreateBitmapFromFile("haystack.png")
phaystack:=Gdip_BitmapFromScreen()

Gdip_GetImageDimensions(phaystack , wh, hh)

pGraphics:=Gdip_GraphicsFromImage(phaystack)

pBrush:=Gdip_BrushCreateSolid(0xff000000)


loop 40 ;just to be safe
{
    Gdip_ImageSearch(phaystack ,pneedle,list,0,0,wh,hh,10,,,1)
    
    if !regexmatch(list,"\d")
    break
   
    l .=list "`n"
    pos:=strsplit(list,",")
    
    Gdip_FillRectangle(pGraphics, pBrush, pos.1,pos.2, wn, hn)

}
;Gdip_SaveBitmapToFile(phaystack,"tn.png")
msgbox % l


Gdip_DisposeImage(phaystack)
Gdip_DisposeImage(pneedle)
Gdip_DeleteGraphics(pGraphics)
Gdip_DeleteGraphics(g)
Gdip_Shutdown(pToken)
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: Gdip_ImageSearch, i am unable to find all instances

07 Dec 2017, 05:18

Wow, great explanation with transcolor, now clearly i can see why i cant get it in the first place.
Thanks noname, Works perfectly.

Surely your response answered many questions, thanks for all the help, cheers, have a great day
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: Gdip_ImageSearch, i am unable to find all instances

11 Dec 2017, 07:58

Hi,

I have a question, is it impossible to search an exact image(not like color or pixel search but with the image) in group, i found that it is difficult. I hope not impossible.

single image found - yes
in group - no
Attachments
N.jpg
Needle
N.jpg (2.17 KiB) Viewed 1818 times
H.jpg
haystack
H.jpg (10.96 KiB) Viewed 1818 times
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Gdip_ImageSearch, i am unable to find all instances

11 Dec 2017, 09:07

Image

The needle image is not the same as the composite , if you crop the border, it will find it even with the simple standard ahk imagesearch without having to use variation.
rakesha002
Posts: 46
Joined: 04 Dec 2017, 00:11

Re: Gdip_ImageSearch, i am unable to find all instances

11 Dec 2017, 11:24

how silly my doubt is, sorry i am new to this image searching,
thanks for the quick reply and pointing me in right direction.

have a great day.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mikeyww, scriptor2016 and 278 guests