70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
"""定位 find_blocking_modal_close 的误判点,并把命中位置标注成图片。"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
import numpy as np
|
|
from PIL import Image, ImageDraw
|
|
|
|
import wechat_bot as bot_module
|
|
|
|
|
|
def main():
|
|
activate = "--activate" in sys.argv
|
|
bot = bot_module.WeChatBot()
|
|
bot.safe_window_mode = True
|
|
bot.auto_activate_window = activate
|
|
if not bot.connect(activate=False, wait_if_missing=False):
|
|
print("[-] 未挂载到企业微信窗口")
|
|
return
|
|
if activate:
|
|
print(f"_ensure_visible(): {bot._ensure_visible()}")
|
|
full = bot._capture_full_window()
|
|
bot._refresh_message_geometry(full)
|
|
|
|
full = bot._capture_full_window()
|
|
print(f"窗口画面: {full.shape}")
|
|
print(f"_message_nav_selected : {bot._message_nav_selected(full)}")
|
|
print(f"looks_like_security_verify : {bot_module.looks_like_security_verification(full)}")
|
|
|
|
hit = bot_module.find_blocking_modal_close(full)
|
|
print(f"find_blocking_modal_close : {hit}")
|
|
|
|
height, width = full.shape[:2]
|
|
print(f"搜索区域 x: {int(width * 0.40)} ~ {int(width * 0.88)}")
|
|
print(f"搜索区域 y: {int(height * 0.08)} ~ {int(height * 0.58)}")
|
|
|
|
out = Image.fromarray(full[:, :, :3][:, :, ::-1])
|
|
draw = ImageDraw.Draw(out)
|
|
draw.rectangle(
|
|
[int(width * 0.40), int(height * 0.08), int(width * 0.88), int(height * 0.58)],
|
|
outline=(0, 128, 255),
|
|
width=3,
|
|
)
|
|
if hit is not None:
|
|
cx, cy = hit
|
|
draw.ellipse([cx - 40, cy - 40, cx + 40, cy + 40], outline=(255, 0, 0), width=5)
|
|
draw.line([cx - 70, cy, cx + 70, cy], fill=(255, 0, 0), width=2)
|
|
draw.line([cx, cy - 70, cx, cy + 70], fill=(255, 0, 0), width=2)
|
|
print(f"命中窗口内坐标: ({cx}, {cy}) 屏幕坐标: ({bot.L + cx}, {bot.T + cy})")
|
|
print(f"相对宽高比例: x={cx / width:.3f} y={cy / height:.3f}")
|
|
patch = full[max(0, cy - 30):cy + 30, max(0, cx - 30):cx + 30]
|
|
Image.fromarray(patch[:, :, :3][:, :, ::-1]).resize(
|
|
(patch.shape[1] * 6, patch.shape[0] * 6), Image.NEAREST
|
|
).save(os.path.join(os.path.dirname(os.path.abspath(__file__)), "modal_hit_zoom.png"))
|
|
print("局部放大图: tmp/modal_hit_zoom.png")
|
|
|
|
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "modal_probe.png")
|
|
out.save(path)
|
|
print(f"整窗标注图: {path}")
|
|
|
|
# 弹窗判定被限频复用的签名,解释为什么有些轮次一句日志都不打就退出。
|
|
print(f"_ui_guard_surface_signature: {bot._ui_guard_surface_signature(full)}")
|
|
print(f"BLOCKER_RETRY_SECONDS : {bot_module.BLOCKER_RETRY_SECONDS}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|