From f5bfcb56ebccb9bf5f25759c00c279ef4d1f2eb1 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Tue, 28 Jul 2026 12:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=EF=BC=9AOCR=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E5=9E=83=E5=9C=BE=EF=BC=88=E5=A6=82544UUJ1W?= =?UTF-8?q?=20H=20V=3DYJ~JL:e=EF=BC=89=E6=BC=8F=E8=BF=87=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:EasyOCR对头像/表情/特殊UI区域输出无意义字母数字符号组合, _is_ocr_console_garbage对无中文文本阈值>20,刚好漏过20字符的乱码。 修复: 1. 无中文阈值从>20降到>15 2. 新增随机字符检测:无中文+特殊字符>15%+字母数字混杂→垃圾 3. _process_ocr_output逐行过滤同步添加该检测 --- monitor.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index a8f6a65..a20e277 100644 --- a/monitor.py +++ b/monitor.py @@ -579,10 +579,19 @@ class MessageMonitor: for pat in garbage_patterns: if re.search(pat, text, re.IGNORECASE): return True - # 全字母数字+标点无中文 → 肯定是非聊天内容 cjk_count = sum(1 for c in text if '\u4e00' <= c <= '\u9fff') - if cjk_count == 0 and len(text.strip()) > 20: + # 全字母数字+标点无中文 → 肯定是非聊天内容(阈值降到 15) + if cjk_count == 0 and len(text.strip()) > 15: return True + # OCR 随机字符垃圾:无中文 + 特殊字符比例高(如 = ~ @ # $ % ^ & *) + # EasyOCR 在包含头像/表情/特殊 UI 的区域会输出 544UUJ1W H V=YJ~JL:e 这类乱码 + if cjk_count == 0 and len(text.strip()) >= 8: + special_chars = sum(1 for c in text if c in '=~@#$%^&*_+{}[]|\\<>/`!') + alpha_count = sum(1 for c in text if c.isalpha()) + digit_count = sum(1 for c in text if c.isdigit()) + # 特殊字符占比过高(>15%)且字母数字混杂 → OCR 乱码 + if special_chars / len(text) > 0.15 and alpha_count >= 2 and digit_count >= 2: + return True return False def _validate_qq_window(self, hwnd: int) -> bool: @@ -1065,6 +1074,15 @@ class MessageMonitor: # OCR 碎片:≤8 字符且无中文 → 时间戳/checkbox 残片 if len(line) <= 8 and not re.search(r'[\u4e00-\u9fff]', line): continue + # OCR 随机字符垃圾:无中文 + 特殊字符比例高(如 `544UUJ1W H V=YJ~JL:e`) + # EasyOCR 对头像/表情/特殊 UI 区域会输出这类无意义字母数字符号组合 + if not re.search(r'[\u4e00-\u9fff]', line) and len(line) >= 10: + special_chars = sum(1 for c in line if c in '=~@#$%^&*_+{}[]|\\<>/`') + alpha_count = sum(1 for c in line if c.isalpha()) + digit_count = sum(1 for c in line if c.isdigit()) + if special_chars / len(line) > 0.15 and alpha_count >= 2 and digit_count >= 2: + logger.debug(f"[{platform}] OCR 过滤: 随机字符垃圾 line={line!r}") + continue # checkbox 残片:`[V]` `[X]` `[√]` 开头,明显不是用户提问 if re.match(r'^\[[VX√✗]\s*\](?:\s*[A-Za-z0-9_\-./]+)?\s*$', line): logger.debug(f"[{platform}] OCR 过滤: checkbox残片 line={line!r}")