【发布时间】:2022-08-09 15:56:27
【问题描述】:
我正在尝试使用存储库中库 pytesseract 中的函数 image_to_string 来执行 PDF 的 OCR。但是,我收到以下错误:
从检查中我会假设库已正确加载:
有谁知道如何在这里解决问题?
标签: tesseract python-tesseract palantir-foundry foundry-code-repositories
我正在尝试使用存储库中库 pytesseract 中的函数 image_to_string 来执行 PDF 的 OCR。但是,我收到以下错误:
从检查中我会假设库已正确加载:
有谁知道如何在这里解决问题?
标签: tesseract python-tesseract palantir-foundry foundry-code-repositories
Foundry 似乎不尊重/运行环境激活脚本
https://github.com/conda-forge/tesseract-feedstock/blob/main/recipe/activate.sh
自动设置TESSDATA_PREFIX 环境变量。但是,我们可以手动推断该值并将其提供给 pytesseract API 调用。
定义以下辅助函数:
def _get_tessdata_directory_path():
import sys
from pathlib import Path
env_root = Path(sys.executable).parent.parent
share_dir = env_root / 'share' / 'tessdata'
assert share_dir.exists(), 'tessdata directory does not exist in <envroot>/share/tessdata'
return str(share_dir)
并像下面的 sn-p 所示使用它:
tessdata_dir_config = f'--tessdata-dir "{_get_tessdata_directory_path()}"'
pytesseract.image_to_string(image, ..., config=tessdata_dir_config)
【讨论】: