'commit'
This commit is contained in:
BIN
WeiXin/Screenshots/T6_debug_view.jpg
Normal file
BIN
WeiXin/Screenshots/T6_debug_view.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
WeiXin/Screenshots/t6_live_shot.jpg
Normal file
BIN
WeiXin/Screenshots/t6_live_shot.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
87
WeiXin/T6_CV_Voice_Debug.py
Normal file
87
WeiXin/T6_CV_Voice_Debug.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
import cv2
|
||||
import uiautomator2 as u2
|
||||
|
||||
# 添加项目根目录到 sys.path
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if project_root not in sys.path:
|
||||
sys.path.append(project_root)
|
||||
|
||||
from WeiXin.WxUtil import find_all_template_matches
|
||||
|
||||
|
||||
def run_cv_debug():
|
||||
# 1. 拍照 (获取当前设备屏幕)
|
||||
print("📸 正在连接设备并截取屏幕...")
|
||||
try:
|
||||
d = u2.connect()
|
||||
screenshot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Screenshots")
|
||||
if not os.path.exists(screenshot_dir):
|
||||
os.makedirs(screenshot_dir)
|
||||
|
||||
image_path = os.path.join(screenshot_dir, "t6_live_shot.jpg")
|
||||
output_path = os.path.join(screenshot_dir, "T6_debug_view.jpg")
|
||||
|
||||
d.screenshot(image_path)
|
||||
print(f"✅ 截图已保存: {image_path}")
|
||||
except Exception as e:
|
||||
print(f"❌ 拍照失败: {e}")
|
||||
return
|
||||
|
||||
print(f"🔍 正在分析实时图片...")
|
||||
|
||||
# 模板路径
|
||||
audio_template = r"d:\dsWork\aiData\WeiXin\Templates\audio.jpg"
|
||||
red_point_template = r"d:\dsWork\aiData\WeiXin\Templates\red_point.jpg"
|
||||
|
||||
if not os.path.exists(audio_template) or not os.path.exists(red_point_template):
|
||||
print("错误: 模板文件不存在")
|
||||
return
|
||||
|
||||
# 2. 识别逻辑
|
||||
audio_matches = find_all_template_matches(image_path, audio_template, threshold=0.8)
|
||||
red_points = find_all_template_matches(image_path, red_point_template, threshold=0.8)
|
||||
|
||||
print(f"发现语音图标数量: {len(audio_matches)}")
|
||||
print(f"发现红点数量: {len(red_points)}")
|
||||
|
||||
# 3. 读取图片并绘制
|
||||
img = cv2.imread(image_path)
|
||||
if img is None:
|
||||
print("错误: 无法读取图片")
|
||||
return
|
||||
|
||||
for ax, ay in audio_matches:
|
||||
# 排除顶部标题栏和底部输入区 (假设 300-1800 为有效区)
|
||||
if ay < 300 or ay > 1800:
|
||||
continue
|
||||
|
||||
sender = "对方" if ax < 500 else "我"
|
||||
is_unread = False
|
||||
|
||||
# 1. 绘制语音图标绿框 (根据模板大小,假设 60x60)
|
||||
cv2.rectangle(img, (int(ax-30), int(ay-30)), (int(ax+30), int(ay+30)), (0, 255, 0), 3)
|
||||
|
||||
# 2. 绘制模拟点击红点 (用户要求用红点标出模拟点击位置)
|
||||
cv2.circle(img, (int(ax), int(ay)), 15, (0, 0, 255), -1)
|
||||
|
||||
# 3. 检查并标记未读红点 (如果存在)
|
||||
for rx, ry in red_points:
|
||||
if abs(ry - ay) < 50 and rx > ax:
|
||||
is_unread = True
|
||||
# 绘制未读红点
|
||||
cv2.circle(img, (int(rx), int(ry)), 12, (0, 0, 255), -1)
|
||||
break
|
||||
|
||||
print(f"标注语音消息: ({ax}, {ay}), 发送者: {sender}, 未读: {is_unread}")
|
||||
|
||||
# 保存结果
|
||||
cv2.imwrite(output_path, img)
|
||||
print(f"✅ 调试图片已保存至: {output_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_cv_debug()
|
||||
@@ -15,7 +15,7 @@ if project_root not in sys.path:
|
||||
|
||||
from Util import Win32Patch
|
||||
|
||||
from WeiXin.WxUtil import perform_input_action, clean_screenshots_dir, is_in_chat_interface, find_template_match, find_all_template_matches
|
||||
from WeiXin.WxUtil import perform_input_action, clean_screenshots_dir, find_template_match, find_all_template_matches
|
||||
from Util.LlmUtil import get_llm_response
|
||||
from Util.EasyOcrKit import EasyOcrKit
|
||||
|
||||
@@ -255,14 +255,8 @@ class ChatBot:
|
||||
|
||||
while True:
|
||||
try:
|
||||
# 0.5 检查是否在聊天界面
|
||||
if not is_in_chat_interface(self.d):
|
||||
logger.warning("📵 当前不在聊天界面,跳过扫描...")
|
||||
await asyncio.sleep(CHECK_INTERVAL)
|
||||
continue
|
||||
|
||||
logger.info("🔍 正在扫描当前界面内容...")
|
||||
|
||||
|
||||
# 1. 截图
|
||||
tmp_shot = os.path.join(self.screenshot_dir, "t6_monitor_temp.jpg")
|
||||
logger.info(f"📸 正在截取屏幕... ({datetime.now().strftime('%H:%M:%S')})")
|
||||
@@ -340,10 +334,10 @@ class ChatBot:
|
||||
click_x, click_y = ax, ay
|
||||
|
||||
# 绘制视觉反馈
|
||||
# 语音图标用绿框
|
||||
# 1. 语音图标用绿框
|
||||
cv2.rectangle(debug_img, (int(ax-30), int(ay-30)), (int(ax+30), int(ay+30)), (0, 255, 0), 3)
|
||||
# 点击位置用红十字
|
||||
cv2.drawMarker(debug_img, (int(click_x), int(click_y)), (0, 0, 255), cv2.MARKER_CROSS, 35, 3)
|
||||
# 2. 点击位置用红点 (用户偏好)
|
||||
cv2.circle(debug_img, (int(click_x), int(click_y)), 15, (0, 0, 255), -1)
|
||||
|
||||
v_msg = {
|
||||
"type": "voice",
|
||||
Binary file not shown.
Reference in New Issue
Block a user