'Python - Determining which of three different, but simlar photos, are currently on the screen - in a quick manner
I'm quite new to Python and am currently in the process of trying to write a script to automatically go through a simple dungeon in a browser pokémon game. There are three different dungeon types, all with different grids, meaning they need different paths to traverse them. I want my script to be able to differentiate between these three dungeons and one of the only visual differences I have been able to find was the layout which looks like this:
Currently, it works to search the whole screen to find one of the pictures, but the script has a hard time differentiating between the pictures since they are so similar.
The code I'm currently using is:
def identifyDungeon(mapIcon):
time.sleep(0.5)
left = mapIcon[0]-50
top = mapIcon[1]
width = 630
height = 250
conf1 = 0.8
conf2 = 0.8
conf3 = 0.8
isItASmallDungeon = pyautogui.locateOnScreen('dungeonSmall.png', confidence=conf1, region=(left, top, width, height))
isItAMediumDungeon = pyautogui.locateOnScreen('dungeonMedium.png', confidence=conf2, region=(left, top, width, height))
isItALargeDungeon = pyautogui.locateOnScreen('dungeonLarge.png', confidence=conf3, region=(left, top, width, height))
(mapIcon is an anchor point I use to determine the region to search within, which I'm currently also having issues with, but that's a problem for later.)
It doesn't work to play with the confidence, since it will sometimes find
- All of them, while only one of them is present on the screen
- None of them, while one is present on the screen
- One of them, but not the one present on the screen
- The one present on the screen AND one not
- Etc.
Is there another way to handle this problem? How would you guys do this?
Best of luck, I'm probably just doing something obvious wrong :P
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
