diff --git a/README.md b/README.md index 935b768..fdc382d 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ wait_for_text("结算") -> 轮询直到文字出现/消失 `LCP_PLATFORM=win|linux|mac` 强制指定,默认按系统自动检测。 -OCR 服务默认 http://35.212.193.150:8599/(gcp1 上的 RapidOCR,客户端零安装), -可 `OCR_URL` 覆盖。 +OCR 全本地:`ocr_local.py` 调 Windows 自带 OCR(Windows.Media.Ocr,需 `pip install --user winsdk`)。 +无任何云端/远端服务依赖——MCP 是纯本地"外骨骼"。 ## 部署 @@ -54,8 +54,7 @@ OCR 服务默认 http://35.212.193.150:8599/(gcp1 上的 RapidOCR,客户端 |------|------|------| | `LCP_PLATFORM` | 自动 | win/linux/mac | | `INPUT_BACKEND` | 平台默认 | mock/sendinput/interception/xdotool/uinput/cg | -| `OCR_BACKEND` | auto | local(Windows自带OCR,winsdk) / remote(gcp1) / auto(本地可用优先) | -| `OCR_URL` | gcp1:8599 | remote 后端的 OCR 服务(OCR_BACKEND=local 时用不到) | +| `OCR_BACKEND` | local | 本地 OCR(仅 local;Win 需 winsdk) | | `OCR_MIN_SCORE` | 0.5 | 过滤低置信度 OCR 结果 | ## 工具 diff --git a/lc_mcp.py b/lc_mcp.py index 669c4dc..2d00131 100644 --- a/lc_mcp.py +++ b/lc_mcp.py @@ -17,13 +17,11 @@ import os import sys import json import time -import urllib.request from platform import detect_platform, get_input_backend, get_screenshot_provider BACKEND_NAME = os.environ.get('INPUT_BACKEND', '').strip().lower() -OCR_URL = os.environ.get('OCR_URL', 'http://35.212.193.150:8599/').strip().rstrip('/') + '/' -OCR_BACKEND = os.environ.get('OCR_BACKEND', 'auto').strip().lower() +OCR_BACKEND = os.environ.get('OCR_BACKEND', 'local').strip().lower() MIN_SCORE = float(os.environ.get('OCR_MIN_SCORE', '0.5')) BASE = os.path.join(os.path.expanduser('~'), 'lc_mcp') os.makedirs(BASE, exist_ok=True) @@ -38,36 +36,14 @@ def log(msg): def ocr_image(img_path): - """OCR 分发:local(winsdk/Win自带) / remote(gcp1)。 - OCR_BACKEND=auto: 本地可用则本地, 否则远端。""" - impl = None - if OCR_BACKEND == 'local' or OCR_BACKEND == 'auto': - try: - import ocr_local - if ocr_local.available(): - impl = ('local', ocr_local) - except Exception: - impl = None - if impl is None and OCR_BACKEND != 'local': - impl = ('remote', None) - if impl is None: - return None, 'no usable OCR backend (OCR_BACKEND=%s)' % OCR_BACKEND - - kind, mod = impl - if kind == 'local': - items, err = mod.ocr_image(img_path) - else: - with open(img_path, 'rb') as f: - body = f.read() - req = urllib.request.Request(OCR_URL, data=body, headers={'Content-Type': 'image/png'}) - try: - with urllib.request.urlopen(req, timeout=30) as resp: - data = json.loads(resp.read().decode('utf-8')) - except Exception as e: - return None, 'ocr call fail: %s' % e - if not data.get('ok'): - return None, data.get('error', 'ocr error') - items = data.get('items', []) + """本地 OCR(Windows 自带 OCR,winsdk;无任何云端依赖)。""" + try: + import ocr_local + except Exception as e: + return None, 'ocr_local import fail: %s' % e + if not ocr_local.available(): + return None, 'winsdk 不可用: pip install --user winsdk' + items, err = ocr_local.ocr_image(img_path) if items is None: return None, err items = [it for it in items if float(it.get('score', 1)) >= MIN_SCORE] @@ -191,7 +167,7 @@ def send(obj): def main(): platform = detect_platform() - log('lc_mcp v0.5 platform=%s backend=%s ocr=%s' % (platform, BACKEND_NAME or 'auto', OCR_URL)) + log('lc_mcp v0.5 platform=%s backend=%s ocr=%s' % (platform, BACKEND_NAME or 'auto', OCR_BACKEND)) backend = None try: provider = get_screenshot_provider(platform)