May somebody help me with this ImageSearch script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

May somebody help me with this ImageSearch script?

11 Dec 2018, 12:43

Hi forum,

At the moment i am trying to write a script which would help me in a game. I want it to look for special bases on the map in the game Goodgame Empire (i attached pictures of it to this post). I am looking for free food bases (not castles). Occupied bases look almost the same but they have a flag and small tents around and are for the moment not what i am looking for.

I tried to do it on my own but i failed. Either the ImageSearch command is not accurate enough or i am failing miserably. I was using a png of the free base with tranparent background for the script. As soon as i tested the script and opened the image in Paint and made the background for example black it didnt recognize it. The script and the image are saved in the same folder on my pc by the way. As you can see in the map picture i attached there is also some kind of background ingame which doesnt make it easier.

After the script searched on the current screen for the image it should press the right arrow for lets say one second (to got to the right on the map) and look for a free base again.

Is there anyone who can help me improving my script?

Thats what i have done so far:

Code: Select all

^j::
CoordMode, Pixel
IfNotExist, rsdfuttertrans.png
	MsgBox Error: Your file either doesn't exist or isn't in this location.
lookForIns:
Loop{
	ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 rsdfuttertrans.png
	SoundBeep, 200, 400
	send, {right down}
	sleep, 1000
	send, {right up}
}
until, ErrorLevel = 0
MsgBox The picture has been found at %x%x%y%.
SoundBeep, 400, 200
sleep, 100
SoundBeep, 400, 200
ExitApp
Return

^h::
SoundBeep, 150, 1000
ExitApp
Return
Thanks for you time
hanslhansl
Attachments
rsdfuttertrans.png
thats the transparent picture of a free food base
rsdfuttertrans.png (4.7 KiB) Viewed 1238 times
Ausgangsfoto.png
thats what free food bases look like ingame (the ones with flags belong to other people)
Ausgangsfoto.png (5.02 KiB) Viewed 1238 times
Unbenannt.png
thats how the map looks like but its at least a 1000 times bigger (i zoomed out as far as possible)
Unbenannt.png (592.78 KiB) Viewed 1238 times
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: May somebody help me with this ImageSearch script?

11 Dec 2018, 13:19

i dont see any such bases in this image uve attached here, so how are we supposed to test it
ur free base img is colored differently than the bases on the larger img. variation may or may not help to alleviate this issue
ull also need the *TransWhite flag to handle the transparency
the bases also seem to be sized a bit differently too
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

11 Dec 2018, 14:11

swagfag wrote:
11 Dec 2018, 13:19
i dont see any such bases in this image uve attached here, so how are we supposed to test it
ur free base img is colored differently than the bases on the larger img. variation may or may not help to alleviate this issue
ull also need the *TransWhite flag to handle the transparency
the bases also seem to be sized a bit differently too
Thank you for your fast answer.
Sorry i forgot to post the link to this webiste with images of free and occupied bases: "http://de.goodgame-empire.wikia.com/wiki/Rohstoffdorf" (scroll down a bit and download the image to display it in its real dimension). If it works there i will adjust the size of the pic the script is looking for with the parameters height and width but that will need more testing.
To be honest i cant see differences regarding the colours. There are three types of bases which look different tough. There is wood, stone and food. At the moment i am only looking for food.
I implemented the *TransWhite parameter. Now it recognizes the transparent image with different background colours but it doesnt recognize the second attached image with the yellow background (thats how it would look ingame) which is strange because it was the initial picture. The transparent one was made out of the yellow one (by me. I didnt add anything. I just deleted the yellow background.).
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: May somebody help me with this ImageSearch script?

11 Dec 2018, 16:35

look
base image u provided
base image from the site u linked
base image of another base, taken from the larger picture directly
u see how in the last one, the bases overlap perfectly? ur haystack image needs to be cropped from the game, not some other side or wherever u took the one u initially provided from. ie, go find an unoccupied base and take a screencap of it. next cut the yellow stuff and replace it with a background color unlikely to appear under normal circumstances, like for example magenta. then use *TransFF00FF and maybe a bit of variation until u can successfully match bases in-game. it is only after uve verified u can achieve that, that u can worry about fleshing the script's core logic out. otherwise, its but a pointless waste of time
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

12 Dec 2018, 04:49

swagfag wrote:
11 Dec 2018, 16:35
look
base image u provided
base image from the site u linked
base image of another base, taken from the larger picture directly
u see how in the last one, the bases overlap perfectly? ur haystack image needs to be cropped from the game, not some other side or wherever u took the one u initially provided from. ie, go find an unoccupied base and take a screencap of it. next cut the yellow stuff and replace it with a background color unlikely to appear under normal circumstances, like for example magenta. then use *TransFF00FF and maybe a bit of variation until u can successfully match bases in-game. it is only after uve verified u can achieve that, that u can worry about fleshing the script's core logic out. otherwise, its but a pointless waste of time
Ok. I got that now. I will look for a free one and implement it as soon as possible. That might take some days though.
Thank you for your help so far.
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

13 Dec 2018, 09:51

swagfag wrote:
11 Dec 2018, 16:35
look
base image u provided
base image from the site u linked
base image of another base, taken from the larger picture directly
u see how in the last one, the bases overlap perfectly? ur haystack image needs to be cropped from the game, not some other side or wherever u took the one u initially provided from. ie, go find an unoccupied base and take a screencap of it. next cut the yellow stuff and replace it with a background color unlikely to appear under normal circumstances, like for example magenta. then use *TransFF00FF and maybe a bit of variation until u can successfully match bases in-game. it is only after uve verified u can achieve that, that u can worry about fleshing the script's core logic out. otherwise, its but a pointless waste of time
Yesterday i found a free base. I experimented a little bit and came to the conclusion that the height and width parameters do not work properly. If the width is 90 (which is the actual width of the image) the image is recognized but if the image is displayed with 200% zoom the script doesnt recognize it even though i increased the width (180 should be the right value. I tried every value between 150 and 210 and nothing worked). Have you got a clue why it isnt working?

I attached a screenshot with the free base, one picture with transparent and one with #FF00FF background (i tried it with both of them).


Thats the updated script:

Code: Select all

CoordMode, Pixel
MsgBox The script has been started.
^j::
width = 50
IfNotExist, kleinstrsdmagenta.png
	MsgBox Error: Your file either doesn't exist or isn't in this location.
lookForIns:
Loop{
	SoundBeep, 200, 400
	MsgBox Look for the image with a width of %width%
	ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, *50 *TransFF00FF *w%width% *h-1 kleinstrsdmagenta.png
	width := ++width

}
until, ErrorLevel = 0
SoundBeep, 400, 200
sleep, 100
SoundBeep, 400, 200
width2 := width - 1
MsgBox The picture has been found at %x%x%y%. The width was %width2%.
Return
Attachments
kleinstrsdtrans.png
transparent background (90x78)
kleinstrsdtrans.png (7.75 KiB) Viewed 1177 times
kleinstrsdmagenta.png
FF00FF background (90x78)
kleinstrsdmagenta.png (7.75 KiB) Viewed 1177 times
ganzer bildschirm 1080p.png
Screenshot (1920x1080)
ganzer bildschirm 1080p.png (1.39 MiB) Viewed 1177 times
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

13 Dec 2018, 10:55

I just discovered a new problem: The occupied bases are basically identical to the free ones. The tents and the flag cover like 1% (the flag post covers a little bit of the roof of the base) or something of the actual base. Meaning that even if if we get it running the script might recognize free and occupied bases as free. But Maybe that 1% is enough...What do you think?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: May somebody help me with this ImageSearch script?

13 Dec 2018, 22:17

search for this bit here, where the flagpole begins:
Spoiler
dont mess with the scaling parameters, theyre meant to be used with icons
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

15 Dec 2018, 15:35

swagfag wrote:
13 Dec 2018, 22:17
search for this bit here, where the flagpole begins:
Spoiler
dont mess with the scaling parameters, theyre meant to be used with icons
I just did that and everything seems fine. But: I had the script run for far more than an hour (i made it change the part of the map seen after it looked for the image) and it didnt find anything. Maybe there simply was no free base or it didnt recegonize it. What i will do now however is to look for another free food base. Then i will create a new image with the parts that exist in both of the images with free bases. When i managed do that i will post whether it worked or it didnt. Might take some time though...
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

18 Dec 2018, 12:38

swagfag wrote:
13 Dec 2018, 22:17
search for this bit here, where the flagpole begins:
Spoiler
dont mess with the scaling parameters, theyre meant to be used with icons
Due to a bug in the game i managed to get an image with lots of free bases (i attached it). I used the part you showed me of 6 different bases and scanned the screenshot. With one of the 6 images i got 27 matches (out of 48). I think it wont get any better. I used a variation of 50 for the test. At the moment i am trying to increase it a bit but at the same time it shouldnt recognize occupied bases (which it doesnt with a variation of 50). Lets see how much i can increase.

Edit: I just realized i cant add the screenshot with 48 free bases which resulted out of a bug...
Attachments
foundwith_rsd1(f14+s7+w6=27[bad quality]).jpg
here you can see which bases have been found. 14 food, 7 stone and 6 wood bases out of 48
foundwith_rsd1(f14+s7+w6=27[bad quality]).jpg (545.53 KiB) Viewed 1069 times
1440prsdwüste48 bases total(bad_qualitiy).jpg
its a jpg now bc the png was to big i think. might not be full qualitiy
1440prsdwüste48 bases total(bad_qualitiy).jpg (526.66 KiB) Viewed 1069 times
rsd1.png
27 found
rsd1.png (1.06 KiB) Viewed 1082 times
hanslhansl
Posts: 8
Joined: 11 Dec 2018, 03:54

Re: May somebody help me with this ImageSearch script?

18 Dec 2018, 13:32

It seems like i did it now. With a variation of 80 i found 40 of 48 in the picture and the script still works as intended. Thank you so much for your help. It would not have been possible without you :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DataLife, Google [Bot], pgeugene, Rohwedder and 53 guests