This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
gbc/main.py

38 lines
996 B
Python
Raw Permalink Normal View History

2023-09-24 01:27:02 +02:00
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__":
2023-09-24 01:29:33 +02:00
print("Running...")
2023-09-24 01:27:02 +02:00
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)
2023-09-24 01:32:37 +02:00
threshold = 0.6
2023-09-24 01:27:02 +02:00
locations = where(result >= threshold)
# Fetch coordinates
2023-09-24 01:29:33 +02:00
locations = list(zip(*locations[::-1]))
2023-09-24 01:27:02 +02:00
2023-09-24 01:29:33 +02:00
# If we find a burger
if len(locations):
2023-09-24 01:35:55 +02:00
x, y = locations[0][0] + 20, locations[0][1] + 10
print(f"Find a golden burger at {x}x{y}")
2023-09-24 01:29:33 +02:00
# Move and click
2023-09-24 01:35:55 +02:00
moveTo(x, y)
2023-09-24 01:29:33 +02:00
click()
2023-09-24 01:27:02 +02:00
# Wait a second every loop
sleep(1)