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