Last active
April 23, 2020 15:35
-
-
Save luminousmen/09dec2e88048d8128a3ad3ebd33c72b2 to your computer and use it in GitHub Desktop.
T-Rex dino game script that will play for you, successfully
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from mss import mss | |
import pyautogui as pg | |
# Please put here you location of t-rex, I used `$ xdotool getmouselocation` for that | |
MONITOR = {"top": 247, "left": 566, "width": 70, "height": 35} | |
def process_image(img): | |
"""Processing image using canny edge detection algorithm | |
:param img: original image | |
:returns: processed image | |
""" | |
processed_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
processed_image = cv2.Canny(processed_image, threshold1=200, threshold2=300) | |
return processed_image | |
def main(): | |
while True: | |
with mss() as sct: | |
img = sct.grab(MONITOR) | |
img = np.array(img) | |
processed_image = process_image(img) | |
mean = np.mean(processed_image) | |
# maybe there is barrier ahead | |
if not mean == float(0): | |
pg.press("space") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment