refactor digging

This commit is contained in:
2022-05-01 17:18:19 +02:00
parent 3691bb9f78
commit 6d6cabfa42

View File

@@ -6,7 +6,7 @@ import cv2 as cv
import pytesseract import pytesseract
from hsvfilter import HsvFilter from hsvfilter import HsvFilter
from config_file import UserConfigs from config_file import UserConfigs
#import pyautogui # import pyautogui
import pydirectinput import pydirectinput
import keyboard import keyboard
from tresh_util import super_tresh_main, super_tresh_needle from tresh_util import super_tresh_main, super_tresh_needle
@@ -16,6 +16,9 @@ def run():
# initialize the user-class # initialize the user-class
config = UserConfigs() config = UserConfigs()
# PLOT_TO_USE = "business"
PLOT_TO_USE = "main_plot"
# initialize the StunWindowCapture class # initialize the StunWindowCapture class
try: try:
capture_window = WindowCapture( capture_window = WindowCapture(
@@ -23,10 +26,13 @@ def run():
video_mode = False video_mode = False
except: except:
# StunWindowCapture.list_window_names() # StunWindowCapture.list_window_names()
#print("Game not running, switching to video mode") # print("Game not running, switching to video mode")
#capture_window = cv.VideoCapture("snip_slam.mp4") # capture_window = cv.VideoCapture("snip_slam.mp4")
video_mode = True video_mode = True
# plot_to_use = "business"
plot_to_use = "main_plot"
# initialize the StunVision class # initialize the StunVision class
vision_stun = Vision() vision_stun = Vision()
# initialize the StunOverlay class # initialize the StunOverlay class
@@ -45,12 +51,10 @@ def run():
pause = False pause = False
print('o pressed') print('o pressed')
if pause: if pause:
#cv.waitKey(500) # cv.waitKey(500)
print("pausing") print("pausing")
continue continue
if video_mode: if video_mode:
break break
else: else:
@@ -62,29 +66,30 @@ def run():
capture_window.release() capture_window.release()
print("Game window not available - shutting down application") print("Game window not available - shutting down application")
break break
#cv.imshow("screenshot", screenshot) # cv.imshow("screenshot", screenshot)
#cv.waitKey(150) # cv.waitKey(150)
#continue # continue
needles = [] needles = []
#needles.append(cv.imread("wtf.jpg", cv.IMREAD_UNCHANGED)) if PLOT_TO_USE == "business":
needles.append(cv.imread("dig/Brown0.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("dig/Brown0.jpg", cv.IMREAD_UNCHANGED))
needles.append(cv.imread("dig/1.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("dig/1.jpg", cv.IMREAD_UNCHANGED))
needles.append(cv.imread("dig/2.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("dig/2.jpg", cv.IMREAD_UNCHANGED))
needles.append(cv.imread("dig/3.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("dig/3.jpg", cv.IMREAD_UNCHANGED))
needles.append(cv.imread("dig/4.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("dig/4.jpg", cv.IMREAD_UNCHANGED))
#needles.append(cv.imread("H1.jpg", cv.IMREAD_UNCHANGED)) else:
#needles.append(cv.imread("H2.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("H1.jpg", cv.IMREAD_UNCHANGED))
#needles.append(cv.imread("H3.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("H2.jpg", cv.IMREAD_UNCHANGED))
#needles.append(cv.imread("H4.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("H3.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D1.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("H4.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D2.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D1.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D3.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D2.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D3.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D3.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D4.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D3.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D5.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D4.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D6.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D5.jpg", cv.IMREAD_UNCHANGED))
# needles.append(cv.imread("D7.jpg", cv.IMREAD_UNCHANGED)) needles.append(cv.imread("D6.jpg", cv.IMREAD_UNCHANGED))
needles.append(cv.imread("D7.jpg", cv.IMREAD_UNCHANGED))
for needle in needles: for needle in needles:
# do object detection # do object detection
@@ -93,9 +98,9 @@ def run():
# draw the detection results onto the original image # draw the detection results onto the original image
if len(rectangles) == 0: if len(rectangles) == 0:
continue continue
#output_image = vision_stun.draw_rectangles(screenshot, rectangles) # output_image = vision_stun.draw_rectangles(screenshot, rectangles)
#cv.imshow("output_image", output_image) # cv.imshow("output_image", output_image)
#cv.waitKey(150) # cv.waitKey(150)
# only trigger ocr reading if a stun is detected # only trigger ocr reading if a stun is detected
points = vision_stun.get_click_points(rectangles) points = vision_stun.get_click_points(rectangles)
@@ -109,8 +114,8 @@ def run():
size = rectangles[0][2] + 1 size = rectangles[0][2] + 1
left = int(round(rectangles[0][0] / size, 0)) # 4 left = int(round(rectangles[0][0] / size, 0)) # 4
down = int(round(rectangles[0][1] / size, 0)) # 23 down = int(round(rectangles[0][1] / size, 0)) # 23
offset_left = config.returnMagicWindowPos()[2] offset_left = config.returnMagicWindowPos()[2]
offset_down = config.returnMagicWindowPos()[3] offset_down = config.returnMagicWindowPos()[3]
# 167 1055 start # 167 1055 start
@@ -131,19 +136,27 @@ def run():
pause = True pause = True
break break
screenshot = capture_window.get_screenshot() if PLOT_TO_USE == "main_plot":
rectangles = vision_stun.find(screenshot, cv.imread("dig/ok_button.jpg", cv.IMREAD_UNCHANGED), 0.8, 1) screenshot = capture_window.get_screenshot()
# draw the detection results onto the original image rectangles = vision_stun.find(screenshot, cv.imread("dig/ok_button.jpg", cv.IMREAD_UNCHANGED), 0.8,
output_image = vision_stun.draw_rectangles(screenshot, rectangles) 1)
if len(rectangles) == 1: # draw the detection results onto the original image
pointis = vision_stun.get_click_points(rectangles) output_image = vision_stun.draw_rectangles(screenshot, rectangles)
for pointi in pointis: if len(rectangles) == 1:
pydirectinput.moveTo(pointi[0] + offset_left, pointi[1] + offset_down) pointis = vision_stun.get_click_points(rectangles)
pydirectinput.mouseDown() for pointi in pointis:
w = random.randint(1, 100) pydirectinput.moveTo(pointi[0] + offset_left, pointi[1] + offset_down)
cv.waitKey(150 + w) pydirectinput.mouseDown()
pydirectinput.mouseUp() w = random.randint(1, 100)
cv.waitKey(150 + w)
pydirectinput.mouseUp()
if keyboard.is_pressed('p') == True or pause == True:
pause = True
break
if keyboard.is_pressed('p') == True or pause == True:
pause = True
break
if keyboard.is_pressed('p') == True or pause == True: if keyboard.is_pressed('p') == True or pause == True:
pause = True pause = True
break break
@@ -154,6 +167,8 @@ def run():
pause = True pause = True
break break
# debug the loop rate # debug the loop rate
print('FPS {}'.format(1 / (time() - loop_time))) print('FPS {}'.format(1 / (time() - loop_time)))
loop_time = time() loop_time = time()