修复OCR乱码+KB全文返回: 裁剪48%+&提前清理+全角:转换+纯时间戳过滤+KB回复限200字
1. cap_left 38%→48%(完全避开会话列表~30-55%)
38%仍捕获到左侧KB预览文字(问题1/2…)混入OCR
48%只捕获消息面板正文,KB预览不再出现
2. &清理移到时间戳分割前+全角:→半角:
原来&在分割后才清理,"13:5&07"无法被时间戳正则捕获
分割前清理→"13:5 07"可匹配时间戳→分割出独立段
全角:统一半角,后续正则只匹配半角
3. 时间戳段用\d{1,2}(允许单数字分钟)
分割后"07""15"等纯数字段被^[\d:\s]+$过滤
之前"13:5 07 14:2 15"整段因含空格,^\d{1,2}[::]\d{2}不匹配
4. auto_reply非Q&A文档回复限200字(之前500仍过多)
子串匹配触发的全文返回只回复前200字符
5. KB行级预览过滤移除(与用户消息混行时误杀)
段级别^问题\d+过滤器已足够,配合新裁剪基本不会触发
This commit is contained in:
+23
-15
@@ -592,11 +592,11 @@ class MessageMonitor:
|
||||
# 先切 QQ 到前台再截屏,避免 CMD 窗口遮挡→OCR 读到终端文字
|
||||
self._ensure_foreground(hwnd)
|
||||
time.sleep(0.15)
|
||||
# 左边界 38%(在会话列表 ~55% 右侧,仅捕获消息面板)
|
||||
# 25% 覆盖联系人+会话列表+消息面板 → OCR 读三面板混合文字(KB预览混入消息)
|
||||
# 38% 从会话列表偏右开始,避开会话列表中的 KB 预览文字
|
||||
# 左边界 48%(消息面板 ~55-100%,完全避开会话列表 ~30-55%)
|
||||
# 38% 还抓到了会话列表右侧的 KB 预览文字(问题1/2…等混入 OCR 文本)
|
||||
# 48% 更深入消息面板,只捕获消息正文区域
|
||||
# 右边界 97%(比 95% 宽 2%),减少右侧时间戳被裁成 & 碎片
|
||||
cap_left = int(left + win_w * 0.38)
|
||||
cap_left = int(left + win_w * 0.48)
|
||||
cap_top = top + max(40, int(win_h * 0.04)) # 标题栏下方
|
||||
cap_right = int(left + win_w * 0.97) # 稍宽避免时间戳裁剪
|
||||
cap_bottom = bottom - max(100, int(win_h * 0.10)) # 输入框上方
|
||||
@@ -643,12 +643,19 @@ class MessageMonitor:
|
||||
expanded = []
|
||||
for rl in ocr_lines:
|
||||
rl = self._normalize_ocr_text(rl)
|
||||
# 先清理 & 碎片(OCR 把时间戳右边缘的 : 读成 &)
|
||||
# 必须在时间戳分割前做,否则 "13:5&07" 无法被时间戳正则捕获
|
||||
rl = rl.replace('&', '')
|
||||
# 把全角 :统一成半角 :,让后续正则统一匹配
|
||||
rl = rl.replace(':', ':')
|
||||
# 分割"msg1 14:24 msg2 13:27 msg3" → ["msg1", "msg2", "msg3"]
|
||||
# re.split 捕获组让时间戳也出现在结果中,用来做分隔边界
|
||||
parts = re.split(r'(\d{1,2}[::]\d{2}(?:[::]\d{2})?)', rl)
|
||||
# 使用更宽松的 \d{1,2}(允许单数字),因为 & 移除后 "5&07"→"507"
|
||||
# 打破的时间戳如 "13:5 07" 也尽量捕获
|
||||
rl = re.sub(r'\s+', ' ', rl) # 多重空格压为一个
|
||||
parts = re.split(r'(\d{1,2}:\d{1,2}(?::\d{1,2})?)', rl)
|
||||
buf = ''
|
||||
for part in parts:
|
||||
if re.match(r'^\d{1,2}[::]\d{2}', part):
|
||||
if re.match(r'^\d{1,2}:\d{1,2}', part):
|
||||
# 遇到时间戳 → 前面的 buf 为一条完整消息
|
||||
if buf.strip():
|
||||
expanded.append(buf.strip())
|
||||
@@ -660,7 +667,7 @@ class MessageMonitor:
|
||||
ocr_lines = expanded
|
||||
texts = []
|
||||
for line in ocr_lines:
|
||||
# 注: OCR 行已在分割时 normalize,此处不再重复 normalize
|
||||
# 注: OCR 行已在分割时 normalize+全角:转换+&清理,此处不再重复
|
||||
if not line:
|
||||
continue
|
||||
# ⭐ QQ NT 界面固定噪声:整行匹配直接跳过
|
||||
@@ -675,11 +682,13 @@ class MessageMonitor:
|
||||
line = re.sub(r'[勖彐"\'\s\u2000-\u206f]+$', '', line)
|
||||
if not line:
|
||||
continue
|
||||
# 过滤 KB 预览文字:"问题1:你叫什么名字答:你好我叫123" — 会话列表显示的 KB 内容
|
||||
if re.match(r'^问题\d+[::]', line):
|
||||
# 过滤 KB 预览文字(行起始): "问题1:你叫什么名字答:你好我叫123"
|
||||
# 注意:行中 KB 预览在分割前 rl 阶段已按整行丢弃,此处只过滤以问题开头的残留
|
||||
if re.match(r'^问题\d+\s*[::]', line):
|
||||
continue
|
||||
# 过滤纯时间戳垃圾:整段只有数字、冒号、空格(如 "13:5 07 14:2 15")
|
||||
if re.match(r'^[\d:\s]+$', line):
|
||||
continue
|
||||
# 过滤仅含时间戳混 & 碎片:"13:5 & 07" — 右侧裁剪导致
|
||||
line = line.replace('&', '')
|
||||
# 半角全角数字混杂的界面碎片(如 "1.0s 0.35后监控应用设置")
|
||||
line = re.sub(r'^\d+[\..]\d+s?\s*\d*[.\.]?\d*', '', line)
|
||||
line = re.sub(r'^[\d.\.\s]{2,20}[一-鿿]{1,5}?[,。、]', '', line)
|
||||
@@ -687,11 +696,10 @@ class MessageMonitor:
|
||||
continue
|
||||
if self._is_system_message(line):
|
||||
continue
|
||||
# ⭐ 纯中文短文本不一定是消息正文——但 1-15 过滤太宽会杀真消息
|
||||
# 改为只过滤单字符纯中文,多字符的 UI 噪声由 _is_system_message 处理
|
||||
# 纯中文短文本(1 字符)— UI 噪声碎片
|
||||
if re.match(r'^[一-鿿]{1}$', line):
|
||||
continue
|
||||
if re.match(r'^\d{1,2}[::\s]\d{2}', line):
|
||||
if re.match(r'^\d{1,2}[::\s]\d{1,2}', line):
|
||||
continue
|
||||
if re.match(r'^\d{4}[/-]\d{1,2}', line):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user