From 0fd4594e44550d1cf61bab28d6dba9f2ba60aea7 Mon Sep 17 00:00:00 2001 From: pbyf83ift <1030227026@qq.com> Date: Tue, 2 Jul 2024 22:03:57 +0800 Subject: [PATCH] ADD file via upload --- control_logic.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 control_logic.py diff --git a/control_logic.py b/control_logic.py new file mode 100644 index 0000000..6954630 --- /dev/null +++ b/control_logic.py @@ -0,0 +1,71 @@ + + +import pyautogui +import time +from tkinter import * + +import cv2 + +import sendinput +from calculate_model import Capture_Point + +from region_detection import Region_Detector + +def show_capture(win_name,roi_image): + cv2.namedWindow(win_name, cv2.WINDOW_NORMAL) + cv2.resizeWindow(win_name, 640, 360) + cv2.imshow(win_name, roi_image) + cv2.moveWindow(win_name, 0,0) + cv2.getWindowImageRect(win_name) + +def main(): + user_interface = Tk() # 界面开头 + user_interface.title("辅助瞄准") + user_interface.geometry("480x640") + user_interface.resizable(0, 0) + Label(user_interface, text='以下是你打开的窗口,请选择要使用的窗口', font=(None, 15), fg='#66CCFF', bg="black").pack() + ht=Region_Detector.getButtonInfo() + + for wnd in ht.items(): + if wnd[1]!= "": + Button(user_interface, text=wnd[1], width=50, height=1, command=lambda wnd=wnd:runhelper(wnd[1]), activeforeground="red", activebackground="black").pack() + + + mainloop() # 界面结尾 + +def runhelper(wn): + win_name = wn + print("现在捕获的窗口是:" ,end="") + print(win_name) + win_size = [1920, 1080] #窗口大小 + win_index = [0,0] #窗口放置位置 + win_more = 0 #窗口多余部分,即窗口标题 + RD = Region_Detector(win_name, win_more) #创建窗口处理对象 + hwdn = RD.getWindowHandle() #获取窗口句柄 + RD.setWindows(hwdn, win_size, win_index) #设置窗口参数 + + while True: + MouseX, MouseY = pyautogui.position() + start_time = time.time() #开始时间 + img, Screen = RD.getWindowsRGB(hwdn) #获取窗口截图 + img_roi, Screen_c,[x0,y0,x1,y1] = RD.getRegion(img, Screen) #获取窗口截图ROI图片 + roi_image,my_result = Capture_Point(img_roi, confidence=0.9) #ROI图像进行推理,返回图像与ROI图像中位置坐标 + print("捕获结果:", my_result) + fps = int(1/(time.time() - start_time)) # 计算推理帧率 + print("处理帧数:{}".format(fps)) + show_capture(win_name, roi_image) # OpenCV窗口显示结果图像 + if cv2.waitKey(1) & 0xFF == ord("q"):#退出快捷键 + break + if my_result == {}: + continue + x= int(my_result["1"][0]) + y = int(my_result["1"][1]) + currentMouseX = (640+x-MouseX)*1.1 + currentMouseY = (360+y-MouseY)*1.1 + sendinput.Mouse.move(int(currentMouseX),int(currentMouseY)) + time.sleep(0.001) + sendinput.Mouse.leftClick() + sendinput.Mouse.leftClick() + sendinput.Mouse.leftClick() + sendinput.Mouse.leftClick() + cv2.destroyAllWindows() \ No newline at end of file