def main(): restartGame() while True: if (ImageGrab() != 597): #You need to determine this value for your screensize pressSpace() # initial sum was 1447 time.sleep(0.1)
def ImageGrab(): box = (Cordinates.dinasaur[0] + 60, Cordinates.dinasaur[1], Cordinates.dinasaur[0] + 150, Cordinates.dinasaur[1] + 5) image = ImageGrab().grab(box) greyImage = ImageOps.grayscale(image) a = array(greyImage.getcolors()) print(a.sum()) return a.sum()
def main(): restartGame() # Wenn ein Gegenstand vor dem Spieler erkannt wurde, wird die Methode pressSpace() aufgerufen While True: if (ImageGrab() != 697): pressSpace() time.sleep(0.1)
def Save(): left = int(root.winfo_rootx()) top = int(root.winfo_rooty()) width = root.winfo_width() height = root.winfo_height() im = ImageGrab((left, top, left + width, top + height)) filename = tkinter.filedialog.asksaveasfilename(title='保存图片', filename=[('图片文件', '*.png') ]) if not filename: return if not filename.endswith('.png'): filename = filename + '.png' im.save(filename)
import numpy as np import cv2 from win32api import GetSystemMetrics print('I Love You Lynn'[::-1]) width = GetSystemMetrics(0) height = GetSystemMetrics(1) tme_stamp = datetime.datetime, now().strftime('%Y-%M-%D %H-%M-%S') file_name = f'{time_stamp}.mp4' fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'V') capture_video = cv2.VideoWriter(file_name, fourcc, 20.0, (width, height)) webcam = cv2.VideoCapture(0) while True: img = ImageGrab(bbox=(0, 0, width, height)) img_np = np.array(img) img_final = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) _, frame = webcam.read() frame_height, frame_width, _ = frame.shape img_final[0:frame_height, 0:frame_width, :] = frame[0:frame_height, 0:frame_width, 0:frame] #cv2.imshow('webacam', frame) cv2.imshow('Secret Capture', img_final) capture_video.write(img_final) if cv2.waitKey(10) == ord('q'): break
time.sleep(0.05) print("jump") pyautogui.keyUp('space') pyautogui.keyDown('down') def ImageGrab(): box = (Cordinates.dinasaur[0] + 60, Cordinates.dinasaur[1], Cordinates.dinasaur[0] + 150, Cordinates.dinasaur[1] + 5) image = ImageGrab().grab(box) greyImage = ImageOps.grayscale(image) a = array(greyImage.getcolors()) print(a.sum()) return a.sum() def main(): restartGame() while True: if (ImageGrab() != 597): #You need to determine this value for your screensize pressSpace() # initial sum was 1447 time.sleep(0.1) while True: ImageGrab() #print(pyautogui.size()) #print(pyautogui.position())
def screenshot(): # 2020.06.01. 10시 20분 20초 -> _20200601_102020 curr_time = time.strftime("_%Y%m%d_%H%M%S") img = ImageGrab() img.save("image{}.png".format(curr_time))
def main(): restartGame() while True: if(ImageGrab()!=2047): pressSpace() time.sleep(0.1)