简体   繁体   English

如何将 tesseract 添加到我的 Docker 容器中,以便我可以使用 pytesseract

[英]How do I add tesseract to my Docker container so i can use pytesseract

I am working on a project that requires me to run pytesseract on a docker container, but am unable to install tesseract onto the container, I also don't know what the file path for pytesseract should be我正在做一个项目,需要我在 docker 容器上运行 pytesseract,但无法将 tesseract 安装到容器上,我也不知道 pytesseract 的文件路径应该是什么

My Dockerfile:我的 Dockerfile:

FROM python:3
ENV PYHTONUNBUFFERED=1
RUN apt-get update && apt-get install -y --no-install-recommends \
      bzip2 \
      g++ \
      git \
      graphviz \
      libgl1-mesa-glx \
      libhdf5-dev \
      openmpi-bin \
      wget \
      python3-tk && \
    rm -rf /var/lib/apt/lists/*
 



WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
ENV QT_X11_NO_MITSHM=1

My pytesseract code:我的 pytesseract 代码:

path_to_tesseract = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
pytesseract.tesseract_cmd = path_to_tesseract

            img=cv2.imread(fpath)
            img=cv2.resize(img,None,fx=2,fy=2, interpolation=cv2.INTER_CUBIC)
            text=pytesseract.image_to_string(img)

I see you are also using opencv.我看到你也在使用 opencv。 The folowing dependency are required to use pytesseract:使用 pytesseract 需要以下依赖项:

FROM python:3.10-slim

ENV PYHTONUNBUFFERED=1
RUN apt-get update \
  && apt-get -y install tesseract-ocr \ # required for pytesseract
  && apt-get -y install ffmpeg libsm6 libxext6 # required for opencv

...
RUN pip install -r requirements.txt

But as you are using docker I would recommend to install opencv-python-headless instead of opencv which is mainly intended for headless environments like Docker.但是当您使用 docker 时,我建议安装opencv-python-headless而不是opencv ,后者主要用于无头环境,如 Docker。 It will come with a precompiled binary wheel and reduce the docker image size.它将带有一个预编译的二进制轮并减小 docker 图像大小。 The Dockerfile will be reduced to: Dockerfile 将减少为:

FROM python:3.10-slim

ENV PYHTONUNBUFFERED=1
RUN apt-get update \
  && apt-get -y install tesseract-ocr

...
RUN pip install -r requirements.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pytesseract:“TesseractNotFound 错误:tesseract 未安装或不在您的路径中”,我该如何解决? - Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? 我可以在 WebApp 中使用 pytesseract 吗? - Can I use pytesseract in a WebApp? 我可以将我的脚本/api 添加到我的 Django 项目中吗? 如果是这样,我该怎么做 - can I add my script/apis to my Django project? If so how can I do this 如何在 docker 容器中使用 plt.savefig() 保存到我的主目录 - How do I use plt.savefig() within docker container to save to my home directory 如何在 Eclipse 中将 PIL 添加到 PyDev,以便我可以导入它并在我的项目中使用它? - How do I add PIL to PyDev in Eclipse, so i could import it and use it in my project? 如何使用 pipenv 将包添加到现有的 docker 容器 - How do I add packages to an existing docker container using pipenv 如何在我的docker容器中运行pycharm? - How do I run pycharm within my docker container? 如何在 Docker Compose 容器中升级到 Python3+ - How do I upgrade to Python3+ in my Docker Compose Container 如何挂载 docker 容器以便我可以运行存储在容器内部的 python 脚本 - How to mount a docker container so that I can run python scripts, which are stored in the inside of the container 如何使用 Python 启动交互式 Docker 容器? - How do I use Python to launch an interactive Docker container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM