main.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # coding=gbk
  2. import numpy as np
  3. import cv2
  4. from PIL import ImageGrab
  5. from win32gui import FindWindow, GetWindowRect
  6. import yolo
  7. import game
  8. import pyautogui
  9. while True:
  10. window_name = "雷电模拟器(64)"
  11. id = FindWindow(None, window_name)
  12. bbox = GetWindowRect(id)
  13. image_array = np.array(ImageGrab.grab(bbox=bbox))
  14. image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2RGB)
  15. image_array, boxes, positions, confidences, classIDs = yolo.yolo_detect(image_array)
  16. yolo.boxes = boxes
  17. yolo.classIDs = classIDs
  18. pos_lead = yolo.get_postition(0) # 主角
  19. pos_stone_green = yolo.get_postition(2) # 蓝宝石指引
  20. pos_stone_yellow = yolo.get_postition(3) # 蓝宝石指引
  21. pos_m1 = yolo.get_postition(15) # 第5级小怪
  22. pos_m2 = yolo.get_postition(16) # 第5级大怪
  23. # if pos_stone_green[0] != 0:
  24. game.move(pos_lead, pos_stone_green)
  25. if pos_m1[0] != 0:
  26. game.strange(pos_lead, pos_m1)
  27. if pos_m2[0] != 0:
  28. game.strange(pos_lead, pos_m2)
  29. cv2.imshow('screenshot', image_array)
  30. if cv2.waitKey(25) & 0xFF == ord('q'):
  31. cv2.destroyAllWindows()
  32. break