加faulthandler+OCR阶段心跳日志排查崩溃
This commit is contained in:
+14
@@ -5,8 +5,11 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
import faulthandler
|
||||||
from typing import Optional, Callable, List
|
from typing import Optional, Callable, List
|
||||||
|
|
||||||
|
faulthandler.enable() # 捕获 C 扩展段错误,输出 traceback 到 stderr
|
||||||
|
|
||||||
logging.getLogger("comtypes").setLevel(logging.WARNING)
|
logging.getLogger("comtypes").setLevel(logging.WARNING)
|
||||||
logger = logging.getLogger("msgbot.monitor")
|
logger = logging.getLogger("msgbot.monitor")
|
||||||
|
|
||||||
@@ -790,20 +793,26 @@ class MessageMonitor:
|
|||||||
# Windows OCR
|
# Windows OCR
|
||||||
if im.mode != 'RGBA':
|
if im.mode != 'RGBA':
|
||||||
im = im.convert('RGBA')
|
im = im.convert('RGBA')
|
||||||
|
logger.debug("[ocr] Windows OCR 开始...")
|
||||||
sb = SoftwareBitmap(BitmapPixelFormat.RGBA8, im.width, im.height)
|
sb = SoftwareBitmap(BitmapPixelFormat.RGBA8, im.width, im.height)
|
||||||
sb.copy_from_buffer(im.tobytes())
|
sb.copy_from_buffer(im.tobytes())
|
||||||
win_result = engine.recognize_async(sb).get()
|
win_result = engine.recognize_async(sb).get()
|
||||||
win_text = win_result.text.strip()
|
win_text = win_result.text.strip()
|
||||||
|
logger.debug(f"[ocr] Windows OCR 完成: {len(win_text)} chars")
|
||||||
|
|
||||||
# EasyOCR 备用
|
# EasyOCR 备用
|
||||||
easy_text = ""
|
easy_text = ""
|
||||||
if _HAS_EASYOCR:
|
if _HAS_EASYOCR:
|
||||||
|
logger.debug("[ocr] EasyOCR 检查/初始化...")
|
||||||
self._init_easyocr()
|
self._init_easyocr()
|
||||||
|
logger.debug("[ocr] EasyOCR reader 就绪状态")
|
||||||
if self._easyocr_reader:
|
if self._easyocr_reader:
|
||||||
try:
|
try:
|
||||||
|
logger.debug("[ocr] EasyOCR 识别开始...")
|
||||||
img_np = _np.array(im)
|
img_np = _np.array(im)
|
||||||
easy_results = self._easyocr_reader.readtext(img_np)
|
easy_results = self._easyocr_reader.readtext(img_np)
|
||||||
easy_text = ' '.join([r[1] for r in easy_results]).strip()
|
easy_text = ' '.join([r[1] for r in easy_results]).strip()
|
||||||
|
logger.debug(f"[ocr] EasyOCR 识别完成: {len(easy_text)} chars")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"[ocr] EasyOCR 识别失败: {e}")
|
logger.debug(f"[ocr] EasyOCR 识别失败: {e}")
|
||||||
|
|
||||||
@@ -895,16 +904,21 @@ class MessageMonitor:
|
|||||||
# ── 双引擎 OCR ──
|
# ── 双引擎 OCR ──
|
||||||
if im.mode != 'RGBA':
|
if im.mode != 'RGBA':
|
||||||
im = im.convert('RGBA')
|
im = im.convert('RGBA')
|
||||||
|
logger.debug("[wechat] Windows OCR 开始...")
|
||||||
sb = SoftwareBitmap(BitmapPixelFormat.RGBA8, im.width, im.height)
|
sb = SoftwareBitmap(BitmapPixelFormat.RGBA8, im.width, im.height)
|
||||||
sb.copy_from_buffer(im.tobytes())
|
sb.copy_from_buffer(im.tobytes())
|
||||||
win_result = engine.recognize_async(sb).get()
|
win_result = engine.recognize_async(sb).get()
|
||||||
win_text = win_result.text.strip()
|
win_text = win_result.text.strip()
|
||||||
|
logger.debug(f"[wechat] Windows OCR 完成: {len(win_text)} chars")
|
||||||
|
|
||||||
easy_text = ""
|
easy_text = ""
|
||||||
if _HAS_EASYOCR:
|
if _HAS_EASYOCR:
|
||||||
|
logger.debug("[wechat] EasyOCR 检查/初始化...")
|
||||||
self._init_easyocr()
|
self._init_easyocr()
|
||||||
|
logger.debug("[wechat] EasyOCR reader 就绪状态")
|
||||||
if self._easyocr_reader:
|
if self._easyocr_reader:
|
||||||
try:
|
try:
|
||||||
|
logger.debug("[wechat] EasyOCR 识别开始...")
|
||||||
img_np = _np.array(im)
|
img_np = _np.array(im)
|
||||||
easy_results = self._easyocr_reader.readtext(img_np)
|
easy_results = self._easyocr_reader.readtext(img_np)
|
||||||
easy_text = ' '.join([r[1] for r in easy_results]).strip()
|
easy_text = ' '.join([r[1] for r in easy_results]).strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user