修:OCR随机字符垃圾(如544UUJ1W H V=YJ~JL:e)漏过过滤
问题:EasyOCR对头像/表情/特殊UI区域输出无意义字母数字符号组合, _is_ocr_console_garbage对无中文文本阈值>20,刚好漏过20字符的乱码。 修复: 1. 无中文阈值从>20降到>15 2. 新增随机字符检测:无中文+特殊字符>15%+字母数字混杂→垃圾 3. _process_ocr_output逐行过滤同步添加该检测
This commit is contained in:
+20
-2
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user