OCR checkbox残片过滤 + EasyOCR GPU自动检测
This commit is contained in:
@@ -9,6 +9,7 @@ build/
|
|||||||
# Virtual environment
|
# Virtual environment
|
||||||
venv/
|
venv/
|
||||||
.venv/
|
.venv/
|
||||||
|
.venv311/
|
||||||
env/
|
env/
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
|
|||||||
+10
-2
@@ -644,8 +644,12 @@ class MessageMonitor:
|
|||||||
# 限制 torch 线程数,避免 MKL/OpenMP 在多线程环境段错误
|
# 限制 torch 线程数,避免 MKL/OpenMP 在多线程环境段错误
|
||||||
import torch
|
import torch
|
||||||
torch.set_num_threads(1)
|
torch.set_num_threads(1)
|
||||||
self._easyocr_reader = _easyocr.Reader(['ch_sim', 'en'], gpu=False)
|
use_gpu = torch.cuda.is_available()
|
||||||
logger.info("[ocr] EasyOCR 就绪(CPU 模式)")
|
self._easyocr_reader = _easyocr.Reader(['ch_sim', 'en'], gpu=use_gpu)
|
||||||
|
if use_gpu:
|
||||||
|
logger.info("[ocr] EasyOCR 就绪(GPU 模式)")
|
||||||
|
else:
|
||||||
|
logger.info("[ocr] EasyOCR 就绪(CPU 模式)")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[ocr] EasyOCR 初始化失败: {e}")
|
logger.error(f"[ocr] EasyOCR 初始化失败: {e}")
|
||||||
self._easyocr_reader = None
|
self._easyocr_reader = None
|
||||||
@@ -1061,6 +1065,10 @@ class MessageMonitor:
|
|||||||
# OCR 碎片:≤8 字符且无中文 → 时间戳/checkbox 残片
|
# OCR 碎片:≤8 字符且无中文 → 时间戳/checkbox 残片
|
||||||
if len(line) <= 8 and not re.search(r'[\u4e00-\u9fff]', line):
|
if len(line) <= 8 and not re.search(r'[\u4e00-\u9fff]', line):
|
||||||
continue
|
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}")
|
||||||
|
continue
|
||||||
if re.match(r'^\d{1,2}[::\s]\d{1,2}', line):
|
if re.match(r'^\d{1,2}[::\s]\d{1,2}', line):
|
||||||
continue
|
continue
|
||||||
if re.match(r'^\d{4}[/-]\d{1,2}', line):
|
if re.match(r'^\d{4}[/-]\d{1,2}', line):
|
||||||
|
|||||||
Reference in New Issue
Block a user