32 lines
811 B
Python
32 lines
811 B
Python
|
from time import sleep
|
||
|
|
||
|
from cv2 import TM_CCOEFF_NORMED, imread, matchTemplate
|
||
|
from numpy import where
|
||
|
from PIL import ImageGrab
|
||
|
from pyautogui import click, moveTo
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
while True:
|
||
|
# Screenshot
|
||
|
screenshot = ImageGrab.grab()
|
||
|
screenshot.save("temp.png")
|
||
|
|
||
|
# Load images
|
||
|
main_image = imread("temp.png")
|
||
|
template_image = imread("goldburger.png")
|
||
|
|
||
|
# Find the burger
|
||
|
result = matchTemplate(main_image, template_image, TM_CCOEFF_NORMED)
|
||
|
threshold = 0.8
|
||
|
locations = where(result >= threshold)
|
||
|
|
||
|
# Fetch coordinates
|
||
|
locations = list(zip(*locations[::-1]))[0]
|
||
|
|
||
|
# Move and click
|
||
|
moveTo(locations[0], locations[1])
|
||
|
click()
|
||
|
|
||
|
# Wait a second every loop
|
||
|
sleep(1)
|