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
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import sys
|
|
sys.path.insert(0, '.')
|
|
from PIL import Image, ImageOps, ImageEnhance
|
|
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
|
|
|
|
im = Image.open('img/raw/qq/ocr_debug_qq_20260818_162956.261.png').convert('RGB')
|
|
# 整条消息区 y=380-740 x=0-739, 温和处理
|
|
for (x0,y0,x1,y1,name,scale) in [
|
|
(0,380,739,740,'bottom_full',2),
|
|
(0,540,739,740,'ts_bottom',3),
|
|
(0,555,430,665,'ts_msg',4),
|
|
(0,665,739,740,'very_bottom',4),
|
|
]:
|
|
crop = im.crop((x0,y0,x1,y1))
|
|
crop8 = crop.resize((crop.width*scale, crop.height*scale), Image.LANCZOS)
|
|
p = f'img/raw/qq/_dbg_{name}.png'
|
|
crop8.save(p)
|
|
try:
|
|
t = ocr_image(p)
|
|
print(f'{name}: {t!r}')
|
|
except Exception as e:
|
|
print(f'{name}: ERROR {e}') |