Files
msgbot/_ocr_blue_test.py
T
youpaishidifu 50474db1c7 修复关键词打分器:时间比较逻辑 + OCR时间源选择
1. 修复 _should_skip_by_time 方法调用参数缺失 text 的问题
2. 实现三源时间比较逻辑:
   - DB落库时间:历史记录的最后处理时间
   - OCR时间:从消息文本提取的时间戳(如'22:54:16')
   - 系统时间:当前机器时间
3. 时间源选择规则:
   - |OCR时间 - 系统时间| ≤ 10秒 → 使用OCR时间(更准确)
   - 否则 → 使用系统时间
4. 重复判断规则:
   - 当前时间 > DB落库时间 + 5分钟 → 放行(新消息)
   - 否则 → 拦截(重复消息)
5. monitor.py 前置 OCR 时间戳提取,传递给打分器
6. 修复 threshold 默认值从 2 改为 1,确保 ≥1 分进入时间比较

参考:Task #1558, #1559
2026-08-18 23:51:57 +08:00

23 lines
841 B
Python

import sys
sys.path.insert(0, '.')
from PIL import Image, ImageOps
from winrt.windows.media.ocr import OcrEngine
from winrt.windows.globalization import Language
from winrt.windows.graphics.imaging import SoftwareBitmap, BitmapPixelFormat
def ocr_image(path):
im = Image.open(path).convert('RGBA')
sb = SoftwareBitmap(BitmapPixelFormat.RGBA8, im.width, im.height)
sb.copy_from_buffer(im.tobytes())
eng = OcrEngine.try_create_from_language(Language('zh-Hans-CN'))
if not eng:
eng = OcrEngine.try_create_from_user_profile_languages()
res = eng.recognize_async(sb).get()
return res.text
for p in ['img/raw/qq/_dbg_msg4_blue.png','img/raw/qq/_dbg_msg4_black.png','img/raw/qq/_dbg_msg4_blue6.png']:
try:
print(f'{p}: {ocr_image(p)!r}')
except Exception as e:
print(f'{p}: ERROR {e}')