fix: 清理HTML标签 + 降低绿色像素阈值 + 增强乱码过滤
1. HTML标签清理: - 在_normalize_ocr_text中清理<br>、<div>等HTML标签 - OCR截到网页/终端时常带HTML标签,影响文本处理 2. 绿色像素检测阈值降低: - 从>=5改为>=3,更敏感地检测微信窗口 - 防止QQ轮询截到微信内容被误处理 3. 乱码过滤增强: - CJK+拉丁混合乱码检测(如'默i'、'鼍') - 生僻字/罕见字检测(CJK扩展区) - 系统配置内容过滤(概览、数据看板、在线玩家等) 4. 解决'牛头不对马嘴'问题: - OCR截到Wiki/终端内容被当用户消息处理 - 知识库匹配到错误的section(Wiki标题而非具体内容)
This commit is contained in:
+21
-1
@@ -829,6 +829,11 @@ class MessageMonitor:
|
||||
# 清理消息末尾的状态标记(如 "0~" "O~" "C~" "0~O~"),避免污染 KB 匹配
|
||||
text = re.sub(r'\s*(?:[A-Za-z0-9]~)+\s*$', '', text)
|
||||
|
||||
# 清理 HTML 标签(OCR 截到网页/终端时常带 <br> <div> 等)
|
||||
text = re.sub(r'<\s*br\s*/?\s*>', '\n', text, flags=re.IGNORECASE)
|
||||
text = re.sub(r'<\s*div\s*/?\s*>', '\n', text, flags=re.IGNORECASE)
|
||||
text = re.sub(r'<[^>]+>', '', text)
|
||||
|
||||
return text.strip()
|
||||
|
||||
@staticmethod
|
||||
@@ -1805,6 +1810,21 @@ class MessageMonitor:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 幻觉乱码(重复) line={line!r}")
|
||||
continue
|
||||
|
||||
# —— OCR 乱码检测:CJK+拉丁混合乱码(如"默i"、"鼍") ——
|
||||
# 正常中文消息不会出现单个拉丁字母夹在CJK之间
|
||||
if re.search(r'[\u4e00-\u9fff][a-zA-Z][\u4e00-\u9fff]', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: CJK+拉丁混合乱码 line={line!r}")
|
||||
continue
|
||||
# 生僻字/罕见字检测:CJK扩展区字符(U+3400-U+4DBF, U+20000-U+2A6DF)
|
||||
if re.search(r'[\u3400-\u4dbf\U00020000-\U0002a6df]', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 生僻字/罕见字 line={line!r}")
|
||||
continue
|
||||
|
||||
# —— 系统配置内容过滤:Wiki/文档页面内容 ——
|
||||
if re.search(r'概览|数据看板|在线玩家|注册用户|活跃玩家|玩家数据', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 系统配置内容(Wiki) line={line!r}")
|
||||
continue
|
||||
|
||||
# —— 回复内容片段检测:OCR 捕获 bot 自己刚发的回复 ——
|
||||
# 用 SequenceMatcher 找 OCR 行与 replied 文本的最长公共子串
|
||||
# 先试原始文本(含字母数字),再试 CJK-only(阈值 6,防短碎片漏网)
|
||||
@@ -2402,7 +2422,7 @@ class MessageMonitor:
|
||||
except:
|
||||
continue
|
||||
total_green = left_green + right_green
|
||||
if total_green >= 5:
|
||||
if total_green >= 3:
|
||||
rlogger.debug(f"[qq] 像素检测: 检测到微信绿色像素(绿={total_green}), 判定为微信窗口, 跳过")
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user