Я провел последний час, исследуя эту простую тему, но все ответы, с которыми я столкнулся, были очень сложными, и, будучи новичком в Python, я не смог включить ни один из них в свою программу.,
Я пытаюсь заставить ИИ играть в браузерную версию игры Piano Tiles.На данный момент я просто пытаюсь сделать снимок игрового окна (небольшая часть экрана моего компьютера), а затем проверить это игровое окно с помощью .png кнопки запуска игры.Оттуда я продолжу щелкать эту кнопку запуска, но это проблема в другой раз.
Как я могу проверить, содержит ли изображение файл .png?
Вот мой текущий код:
from PIL import ImageGrab as ig, ImageOps as io, Image
import pyautogui
import bbox
def grabStart(window):
#The start button
start = Image.open("res/StartButton.PNG")
start = io.grayscale(start)
#This is the part I need to figure out. The following is just pseudocode
if window.contains(start): #I know that this doesn't actually work. Just pseudocode
#I'd like to return the location of 'start' in one of the following forms
return either: (x1, y1, x2, y2), (x1, y1, width, height), (a coordinate within 'start'))
def grabGame():
#The coordinates of the entire game window
x1 = 2222
y1 = 320
x2 = 2850
y2 = 1105
#The entire screen of the game
window = ig.grab(bbox = (x1, y1, x2, y2))
window = io.grayscale(window)
return window
grabStart(grabGame())