Image Search shapes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Image Search shapes

04 Dec 2021, 05:26

Image any idea how can I find this shape with imagesearch? I tried using this one

Image

with this line

Code: Select all

ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%,*TransWhite ./pictures/piece.png
but no luck any idea?
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Image Search shapes

04 Dec 2021, 08:42

Are you sure that each non-white pixel remaining is an exact match for the pixels that make up the black border of the shape? If you used a white paint brush tool to paint over everything up to the border, then you probably left grey pixels where it blends between the two. You have to use a pencil tool that paints only the exact pixel it’s on and leaves the adjacent pixels totally untouched when you get near that black border. That way you are left with only pure white and pixels from the original with their exact color values.

Are the pixels that make up that black border in the image you’re searching for going to be exactly the same no matter what colors surround it? You can’t really answer that by just visual inspection.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: Image Search shapes

04 Dec 2021, 13:25

boiler wrote:
04 Dec 2021, 08:42
Are you sure that each non-white pixel remaining is an exact match for the pixels that make up the black border of the shape? If you used a white paint brush tool to paint over everything up to the border, then you probably left grey pixels where it blends between the two. You have to use a pencil tool that paints only the exact pixel it’s on and leaves the adjacent pixels totally untouched when you get near that black border. That way you are left with only pure white and pixels from the original with their exact color values.

Are the pixels that make up that black border in the image you’re searching for going to be exactly the same no matter what colors surround it? You can’t really answer that by just visual inspection.
well this is the original image of it

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

Re: Image Search shapes

04 Dec 2021, 14:23

I’m not sure what that is. Did you create it? How? Why are the colors reversed?
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: Image Search shapes

05 Dec 2021, 02:36

boiler wrote:
04 Dec 2021, 14:23
I’m not sure what that is. Did you create it? How? Why are the colors reversed?
I saw it in a post where you can locate an image with *TransN and the black or white part will be transparent and it will find the shape of it
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Image Search shapes

05 Dec 2021, 02:51

That is true, but the image you showed is a white outline, and the outline you are looking for is black. So where does that image of a white outline on a black background come from? Are you saying you just reversed the colors? Does doing that result in an exact match of the black outline's color values as the one you are looking to match? You still need to take into account my earlier comments that the original colors of those pixels can't be different than the ones you are searching for, and you can't tell if that's the case just by looking at it unless you zoom way in on it. They have to match the exact color value at every single pixel location or it will not find a match. Even using an allowable variation won't help if one pixel is gray where it should be white.

When I zoom way in on the black outline on white background you showed earlier, it indeed shows lots of gray colors in the transition from black to white (in fact none or almost none are pure black), so it has no chance of being found. Not only that, the image with the colors in it has those colors bleeding into the outline, so those colors aren't pure black or gray either. Because it's so thin, you don't have enough pure colors in this outline to find it using this method. If it was a thicker border, you could paint over the transitions with white, leaving only the center of the line in pure black to be found. But that's not the case here.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: Image Search shapes

07 Dec 2021, 08:33

boiler wrote:
05 Dec 2021, 02:51
That is true, but the image you showed is a white outline, and the outline you are looking for is black. So where does that image of a white outline on a black background come from? Are you saying you just reversed the colors? Does doing that result in an exact match of the black outline's color values as the one you are looking to match? You still need to take into account my earlier comments that the original colors of those pixels can't be different than the ones you are searching for, and you can't tell if that's the case just by looking at it unless you zoom way in on it. They have to match the exact color value at every single pixel location or it will not find a match. Even using an allowable variation won't help if one pixel is gray where it should be white.

When I zoom way in on the black outline on white background you showed earlier, it indeed shows lots of gray colors in the transition from black to white (in fact none or almost none are pure black), so it has no chance of being found. Not only that, the image with the colors in it has those colors bleeding into the outline, so those colors aren't pure black or gray either. Because it's so thin, you don't have enough pure colors in this outline to find it using this method. If it was a thicker border, you could paint over the transitions with white, leaving only the center of the line in pure black to be found. But that's not the case here.
hmm then I should go with python to complete my script
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Image Search shapes

07 Dec 2021, 08:44

99leeroi99 wrote: hmm then I should go with python to complete my script
@malcev posted a link to how you can use OpenCV from AutoHotkey. What method were you going to use in Python?
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: Image Search shapes

08 Dec 2021, 09:08

@boiler
I change my mind in using python because they updated it into new
do you know how to use array? I've been searching through forum and can't find anything about what I'm about to do

there will be like counter

count:=[] ; there will be like 3 of those

there will be loop like 3 times and for the count if the count 1 is empty enter number "number that going to be generated by IMGSEARCH or add it with +" then similar in count 2 and 3e
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Image Search shapes

08 Dec 2021, 09:15

See the section of the documentation on Objects, especially the part on simple arrays. Feel free to ask if you get stuck after reading that.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: Image Search shapes

08 Dec 2021, 10:58

@boiler
as far as it is this is how I understand it

Code: Select all

value:= [num1,num2,num3]
value:= Array (num1,num2,num3)

start:
1:
foundX:=foundX
foundY:=foundY
ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%,*60 ./targets/1.png
If(ErrorLevel = 1){
gosub,2
}
else{
Array[Index] := 1
ToolTip, 1, %foundX%, %foundY%, 1
gosub,2
}

2:
foundX:=foundX
foundY:=foundY
ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%,*60 ./targets/2.png
If(ErrorLevel = 1){
gosub,3
}
else{
Array[Index] := 2
ToolTip, 2, %foundX%, %foundY%, 1
gosub,3
}

3:
foundX:=foundX
foundY:=foundY
ImageSearch, foundX, foundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%,*60 ./targets/3.png
If(ErrorLevel = 1){
gosub,4
}
else{
Array[Index] := 3
ToolTip, 3, %foundX%, %foundY%, 1
gosub,4
}
MSGBOX, % value
and it's not working
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Image Search shapes

08 Dec 2021, 14:08

You haven’t applied those concepts correctly. First you wouldn’t use both methods of the initial assignment, just one or the other. In the second method, don’t put a space after the keyword Array and before the open parenthesis.

You are attempting to initialize the arrays with some values, but you are doing so with some blank values since num1, num2, and num3 don’t contain anything. You mainly just need to declare the array:

Code: Select all

value := []
Then when you refer to the array, its name is value, not Array.

You are attempting to access or assign an element of the array using the variable named index, but nowhere is index assigned a value that I saw.

You did use the array name value with your MsgBox command, but you haven’t identified a specific element of the array. Using the object’s name alone with MsgBox will not display the contents of the array.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], marypoppins_1, OrangeCat and 126 guests