| 123456789101112131415161718192021222324252627282930313233343536373839 |
- # coding=gbk
- import numpy as np
- import cv2
- from PIL import ImageGrab
- from win32gui import FindWindow, GetWindowRect
- import yolo
- import game
- import pyautogui
- while True:
- window_name = "雷电模拟器(64)"
- id = FindWindow(None, window_name)
- bbox = GetWindowRect(id)
- image_array = np.array(ImageGrab.grab(bbox=bbox))
- image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2RGB)
- image_array, boxes, positions, confidences, classIDs = yolo.yolo_detect(image_array)
- yolo.boxes = boxes
- yolo.classIDs = classIDs
- pos_lead = yolo.get_postition(0) # 主角
- pos_stone_green = yolo.get_postition(2) # 蓝宝石指引
- pos_stone_yellow = yolo.get_postition(3) # 蓝宝石指引
- pos_m1 = yolo.get_postition(15) # 第5级小怪
- pos_m2 = yolo.get_postition(16) # 第5级大怪
- # if pos_stone_green[0] != 0:
- game.move(pos_lead, pos_stone_green)
- if pos_m1[0] != 0:
- game.strange(pos_lead, pos_m1)
- if pos_m2[0] != 0:
- game.strange(pos_lead, pos_m2)
- cv2.imshow('screenshot', image_array)
- if cv2.waitKey(25) & 0xFF == ord('q'):
- cv2.destroyAllWindows()
- break
|