Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added config/__pycache__/config.cpython-312.pyc
Binary file not shown.
28 changes: 14 additions & 14 deletions config/config.py
Original file line number Diff line number Diff line change
@@ -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}}
Binary file not shown.
Binary file added core/__pycache__/auto_drawer_scan.cpython-312.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions core/auto_drawer_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added utils/__pycache__/config_help.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/config_utils.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/coord_utils.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/drawing_utils.cpython-312.pyc
Binary file not shown.
Binary file added utils/__pycache__/print_utils.cpython-312.pyc
Binary file not shown.
28 changes: 16 additions & 12 deletions utils/drawing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) 映射到屏幕坐标。
Expand All @@ -32,33 +35,34 @@ 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 \
all(isinstance(i, tuple) and len(i) == 2 for i in path), \
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}")
Expand Down