Files
aiData/WeiXin/T4_CV_Voice_Debug.py
HuangHai a662c33ecf 'commit'
2026-01-26 10:50:11 +08:00

73 lines
2.0 KiB
Python

# coding=utf-8
import os
import sys
import time
import cv2
import logging
# 添加项目根目录到 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 import WxUtil
from WeiXin.WxUtil import find_all_template_matches
# 配置日志
log_dir = WxUtil.LOG_DIR
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(os.path.join(log_dir, "T4_CV_Voice_Debug.log"), encoding='utf-8'),
logging.StreamHandler()
]
)
logger = logging.getLogger("T4_CV_Voice_Debug")
import asyncio
async def run_cv_debug():
# 运行前清理 Logs 和 Output
WxUtil.setup_script_environment()
# 1. 拍照 (获取当前设备屏幕)
logger.info("📸 正在连接设备并截取屏幕...")
d = WxUtil.connect_device()
if not d:
return
try:
screenshot_dir = WxUtil.OUTPUT_DIR
image_path = os.path.join(screenshot_dir, "t4_live_shot.jpg")
output_path = os.path.join(screenshot_dir, "T4_debug_view.jpg")
d.screenshot(image_path)
logger.info(f"✅ 截图已保存: {image_path}")
except Exception as e:
logger.error(f"❌ 拍照失败: {e}")
return
logger.info(f"🔍 正在调用 WxUtil.analyze_chat_image 分析最后一条消息...")
# 2. 调用新的分析逻辑
dialogue_log, input_pos = await WxUtil.analyze_chat_image(image_path, output_path, device=d)
if dialogue_log:
logger.info("📢 识别到的最后一条消息:")
for line in dialogue_log:
logger.info(f" {line}")
else:
logger.warning("⚠️ 未识别到任何消息")
if input_pos:
logger.info(f"📍 识别到输入框位置: {input_pos}")
if __name__ == "__main__":
asyncio.run(run_cv_debug())