'commit'
This commit is contained in:
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()
|
||||
Reference in New Issue
Block a user