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)
@@ -131,8 +136,10 @@ def run():
pause = True pause = True
break break
if PLOT_TO_USE == "main_plot":
screenshot = capture_window.get_screenshot() screenshot = capture_window.get_screenshot()
rectangles = vision_stun.find(screenshot, cv.imread("dig/ok_button.jpg", cv.IMREAD_UNCHANGED), 0.8, 1) rectangles = vision_stun.find(screenshot, cv.imread("dig/ok_button.jpg", cv.IMREAD_UNCHANGED), 0.8,
1)
# draw the detection results onto the original image # draw the detection results onto the original image
output_image = vision_stun.draw_rectangles(screenshot, rectangles) output_image = vision_stun.draw_rectangles(screenshot, rectangles)
if len(rectangles) == 1: if len(rectangles) == 1:
@@ -153,6 +160,14 @@ def run():
if keyboard.is_pressed('p') == True or pause == True: if keyboard.is_pressed('p') == True or pause == True:
pause = True pause = True
break break
if keyboard.is_pressed('p') == True or pause == True:
pause = True
break
if keyboard.is_pressed('p') == True or pause == True:
pause = True
break
# debug the loop rate # debug the loop rate
print('FPS {}'.format(1 / (time() - loop_time))) print('FPS {}'.format(1 / (time() - loop_time)))