diff --git a/config/__pycache__/config.cpython-312.pyc b/config/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000..e3677cc Binary files /dev/null and b/config/__pycache__/config.cpython-312.pyc differ diff --git a/config/config.py b/config/config.py index 9eccd2a..f657613 100644 --- a/config/config.py +++ b/config/config.py @@ -1,14 +1,14 @@ -# -*- coding: utf-8 -*- -CONFIG = {'draw_config': {'DELAY': 3, - 'ENABLE_JITTER': True, - 'JITTER_AMOUNT': 1.5, - 'JITTER_FREQUENCY': 2, - 'SPEED_FACTOR': 1}, - 'image_config': {'BRUSH_STEP': 3, - 'CANNY_THRESH1': 50, - 'CANNY_THRESH2': 150, - 'EPSILON_FACTOR': 0.0001, - 'H_IMG': 1280, - 'THRESHOLD_VALUE': 131, - 'W_IMG': 960}, - 'screen_config': {'H': 0, 'W': 0, 'X_A': 0, 'Y_A': 0}} +# -*- coding: utf-8 -*- +CONFIG = {'draw_config': {'DELAY': 5, + 'ENABLE_JITTER': True, + 'JITTER_AMOUNT': 1.5, + 'JITTER_FREQUENCY': 2, + 'SPEED_FACTOR': 0.1}, + 'image_config': {'BRUSH_STEP': 3, + 'CANNY_THRESH1': 50, + 'CANNY_THRESH2': 150, + 'EPSILON_FACTOR': 0.0001, + 'H_IMG': 1280, + 'THRESHOLD_VALUE': 131, + 'W_IMG': 960}, + 'screen_config': {'H': 910, 'W': 655, 'X_A': 1890, 'Y_A': 365}} diff --git a/core/__pycache__/auto_drawer_canny.cpython-312.pyc b/core/__pycache__/auto_drawer_canny.cpython-312.pyc new file mode 100644 index 0000000..c7eb439 Binary files /dev/null and b/core/__pycache__/auto_drawer_canny.cpython-312.pyc differ diff --git a/core/__pycache__/auto_drawer_scan.cpython-312.pyc b/core/__pycache__/auto_drawer_scan.cpython-312.pyc new file mode 100644 index 0000000..f4b8f64 Binary files /dev/null and b/core/__pycache__/auto_drawer_scan.cpython-312.pyc differ diff --git a/core/auto_drawer_scan.py b/core/auto_drawer_scan.py index 84feea3..3a2e6b9 100644 --- a/core/auto_drawer_scan.py +++ b/core/auto_drawer_scan.py @@ -23,6 +23,8 @@ def __init__(self, config): def run(self, image_path): print_step("加载图像...") img = cv2.imread(image_path) + Wcfg, Hcfg = self.image_config["W_IMG"], self.image_config["H_IMG"] + img = cv2.resize(img, (Wcfg, Hcfg)) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) h, w = gray.shape diff --git a/utils/__pycache__/config_help.cpython-312.pyc b/utils/__pycache__/config_help.cpython-312.pyc new file mode 100644 index 0000000..f36143f Binary files /dev/null and b/utils/__pycache__/config_help.cpython-312.pyc differ diff --git a/utils/__pycache__/config_utils.cpython-312.pyc b/utils/__pycache__/config_utils.cpython-312.pyc new file mode 100644 index 0000000..f286cd1 Binary files /dev/null and b/utils/__pycache__/config_utils.cpython-312.pyc differ diff --git a/utils/__pycache__/coord_utils.cpython-312.pyc b/utils/__pycache__/coord_utils.cpython-312.pyc new file mode 100644 index 0000000..2081c52 Binary files /dev/null and b/utils/__pycache__/coord_utils.cpython-312.pyc differ diff --git a/utils/__pycache__/drawing_utils.cpython-312.pyc b/utils/__pycache__/drawing_utils.cpython-312.pyc new file mode 100644 index 0000000..2d1164a Binary files /dev/null and b/utils/__pycache__/drawing_utils.cpython-312.pyc differ diff --git a/utils/__pycache__/print_utils.cpython-312.pyc b/utils/__pycache__/print_utils.cpython-312.pyc new file mode 100644 index 0000000..4aa701f Binary files /dev/null and b/utils/__pycache__/print_utils.cpython-312.pyc differ diff --git a/utils/drawing_utils.py b/utils/drawing_utils.py index f5bc3ce..bcd865d 100644 --- a/utils/drawing_utils.py +++ b/utils/drawing_utils.py @@ -3,11 +3,14 @@ import time -# 仅使用 pydirectinput 库来模拟鼠标操作 -import pydirectinput -import pydirectinput as mouse_ctrl +# 仅使用 pyautogui 库来模拟鼠标操作 +import pyautogui + from utils.print_utils import print_error, print_warning +pyautogui.FAILSAFE = True +pyautogui.PAUSE = 0.005 + def to_screen_coord(x_img, y_img, image_cfg, screen_cfg): """ 将图像坐标 (x_img, y_img) 映射到屏幕坐标。 @@ -32,12 +35,12 @@ def to_screen_coord(x_img, y_img, image_cfg, screen_cfg): y_screen = Y_A + (y_img / H_IMG) * H return int(round(x_screen)), int(round(y_screen)) def execute_drawing(path, config=None): - press_delay = 0.001 + press_delay = 0.1 if isinstance(config, dict): press_delay = float(config.get("draw_config", {}).get("PRESS_DELAY", press_delay)) - if pydirectinput is None: - raise RuntimeError("execute_drawing: 无法找到 pydirectinput 库") + if pyautogui is None: + raise RuntimeError("execute_drawing: 无法找到 pyautogui 库") try: assert isinstance(path, list) and len(path) >= 2 and \ @@ -45,20 +48,21 @@ def execute_drawing(path, config=None): f"输入参数无效,path 必须是 [(x1, y1), (x2, y2), ...] 格式,但收到 {path}" x_start, y_start = path[0] - pydirectinput.moveTo(int(x_start), int(y_start)) + pyautogui.moveTo(int(x_start), int(y_start)) - pydirectinput.mouseDown() + pyautogui.mouseDown(button='left') + time.sleep(press_delay) for (x, y) in path[1:]: - pydirectinput.moveTo(int(x), int(y)) + pyautogui.moveTo(int(x), int(y),duration=0.01) time.sleep(press_delay) - pydirectinput.mouseUp() + pyautogui.mouseUp(button='left') time.sleep(press_delay) - except pydirectinput.FailSafeException: - print_warning("中止:绘图操作被中断(鼠标移至屏幕角落)") + except pyautogui.FailSafeException: + print_warning("中止:绘图操作被中断") raise except Exception as e: print_error(f"绘制过程出错: {e}")