From a3cc61bd7de9d5293e9d64e85519ccddc9b93e1f Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Sun, 9 Aug 2026 21:11:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BF=BD=E8=B8=AAKB=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=92=8COCR=E8=BF=9E=E7=BB=AD=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gui.py: _search_and_log() 添加KB搜索输入/结果/相关性检查详细日志 - monitor.py: _has_user_colors() 添加像素检测初始化/统计/绿色检测日志 - monitor.py: QQ OCR路径添加截图信息日志 - 目的: 诊断牛头不对马嘴和连续消息OCR中断问题 --- gui.py | 18 ++++++++++++++++++ monitor.py | 24 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gui.py b/gui.py index 8ca69c7..ef500b5 100644 --- a/gui.py +++ b/gui.py @@ -333,17 +333,29 @@ class MsgBotApp(ctk.CTk): def _search_and_log(self, platform: str, msg: str, msg_hash: str): """搜索知识库并输出结果,匹配成功时队列自动回复到主线程""" try: + # 详细调试日志:记录发送给KB搜索的完整消息 + logger.debug(f"[{platform}] KB搜索输入: msg={msg!r} (长度={len(msg)})") + results = self.kb.search(msg, top_k=3) lines = [f"[{platform.upper()}] {msg}"] + if results: answer_title = results[0][0]["title"] answer_score = results[0][1] lines.append(f" 🔍 找到 {len(results)} 条相关结果:") + for i, (doc, score) in enumerate(results): title = doc["title"] heading = doc.get("heading", "") body = doc.get("body", "") content = doc.get("content", "") + + # 详细调试日志:记录每个搜索结果的详细信息 + logger.debug(f"[{platform}] KB结果[{i}]: 标题={title!r}, 匹配度={score:.2f}") + logger.debug(f"[{platform}] KB结果[{i}] heading={heading[:80]!r}") + logger.debug(f"[{platform}] KB结果[{i}] body={body[:120]!r}") + logger.debug(f"[{platform}] KB结果[{i}] content={content[:150]!r}") + # 显示更详细的信息 lines.append(f" 📄 [{title}] (匹配度 {score:.2f})") lines.append(f" 标题: {heading[:60]}") @@ -359,6 +371,12 @@ class MsgBotApp(ctk.CTk): else: # 检查内容相关性 has_relevance = self.ar._has_content_relevance(msg, results[0][0], answer_score) + + # 详细调试日志:记录内容相关性检查结果 + logger.debug(f"[{platform}] 内容相关性检查: msg={msg!r}, has_relevance={has_relevance}") + logger.debug(f"[{platform}] 内容相关性检查: doc标题={results[0][0].get('title', '')!r}") + logger.debug(f"[{platform}] 内容相关性检查: doc heading={results[0][0].get('heading', '')[:50]!r}") + if not has_relevance: heading = results[0][0].get("heading", "")[:40] lines.append(f" ⚠ 内容相关性检查失败 (heading={heading!r}),跳过") diff --git a/monitor.py b/monitor.py index 3df82ea..56addc2 100644 --- a/monitor.py +++ b/monitor.py @@ -2672,6 +2672,12 @@ class MessageMonitor: logger.warning(f"[qq] 截图太小: {im.width}x{im.height}") return [] + # 详细调试日志:记录截图信息和裁剪区域 + logger.debug(f"[qq] OCR前截图信息: 尺寸={im.width}x{im.height}, " + f"窗口位置=({left},{top})-({right},{bottom}), " + f"裁剪区域=({cap_left},{cap_top})-({cap_right},{cap_bottom}), " + f"前台={is_foreground}") + # ⭐ 颜色像素检测:如果截图中只有 bot 蓝色气泡,无白色用户消息,跳过 if not self._has_user_colors(im, "qq"): # ⚠️ 不设 _ocr_unchanged——像素检测失败≠截图没变化。 @@ -4085,6 +4091,10 @@ class MessageMonitor: step_x = max(2, cw // 30) # 增加采样密度,提高白色气泡检测灵敏度 step_y = max(2, ch // 30) + # 详细调试日志:记录截图信息和采样参数 + rlogger = logging.getLogger("msgbot.monitor") + rlogger.debug(f"[{platform}] 像素检测开始: 原始尺寸={w}x{h}, 检测区域={cw}x{ch}, 采样步长=({step_x},{step_y})") + if platform == "qq": # QQ: 蓝色 = bot/对方气泡(右对齐) def is_bot(r, g, b): @@ -4122,11 +4132,11 @@ class MessageMonitor: left_bot, left_other, left_white, left_total = analyze(left_half) right_bot, right_other, right_white, right_total = analyze(right_half) - rlogger = logging.getLogger("msgbot.monitor") - rlogger.debug(f"[{platform}] 像素: 左其它={left_other}/{left_total} " - f"{'自身' if platform=='wechat' else 'bot'}={left_bot} 白={left_white} | " - f"右其它={right_other}/{right_total} " - f"{'自身' if platform=='wechat' else 'bot'}={right_bot} 白={right_white}") + # 详细调试日志:记录像素统计结果 + rlogger.debug(f"[{platform}] 像素统计: 左半区(其他={left_other}/{left_total}, " + f"{'自身' if platform=='wechat' else 'bot'}={left_bot}, 白色={left_white})") + rlogger.debug(f"[{platform}] 像素统计: 右半区(其他={right_other}/{right_total}, " + f"{'自身' if platform=='wechat' else 'bot'}={right_bot}, 白色={right_white})") # ====== 微信专用逻辑 ====== # 颜色语义: @@ -4183,6 +4193,10 @@ class MessageMonitor: except: continue total_green = left_green + right_green + + # 详细调试日志:记录绿色像素检测结果 + rlogger.debug(f"[{platform}] 绿色像素检测: 左绿={left_green}, 右绿={right_green}, 总绿={total_green}") + if total_green >= 3: rlogger.debug(f"[qq] 像素检测: 检测到微信绿色像素(绿={total_green}), 判定为微信窗口, 跳过") return False