Repository navigation
feat(tools): OCR 环境自解析,不再依赖 PATH 与重启 - #11
Merged
Merged
Conversation
装了 tesseract 却仍报 skipped 的真实原因:装机版把 exe 放到 Program Files 但没写进 PATH;中文语言包默认 tessdata 里也没有。已运行的进程环境变量改不了,只能让脚本自己找。 - 新增 resolve_ocr_env():先 shutil.which,再扫 Windows/macOS/Linux 常见安装路径 - 默认 tessdata 缺 chi_sim 时,去找用户级 tessdata 并设 TESSDATA_PREFIX;显式设过的不覆盖 - OCR 段补异常兜底:语言包缺失等错误不再冒泡,降级为 skipped 并给原因 - README 已知限制同步改写 验证:在 PATH 无 tesseract、TESSDATA_PREFIX 为空的进程里跑,OCR 从 skipped 变为 done,识别出中英三行文字;--selftest 4 组仍通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
装完 tesseract 之后
check_image.py的 OCR 仍然是 skipped。原因有两个,都不是「没装」:C:\Program Files\Tesseract-OCR\,但没写进 PATH(机器级和用户级都没有)eng和osd,缺chi_sim;而C:\Program Files不可写,中文包只能放用户目录更关键的是:已运行的进程改不了环境变量。往用户 PATH 写了
C:\Program Files\Tesseract-OCR,也得重开会话才生效。让用户为了跑一次 OCR 去重启,不合理。改动
resolve_ocr_env():先shutil.which,再扫 Windows / macOS / Linux 的常见安装路径chi_sim时,去找用户级 tessdata(%LOCALAPPDATA%\tesseract\tessdata等)并设TESSDATA_PREFIX;环境里已显式设过的不覆盖skipped并给出原因,不假装通过验证
在 PATH 里没有 tesseract、
TESSDATA_PREFIX为空的进程里跑:同一进程里
--selftest的 4 组用例仍全部通过。影响面
只改
check_image.py的 OCR 分支,其余检查项与--fix逻辑不动;OCR 不可用时行为与之前一致(skipped + 原因)。