【问题标题】:How to bundle tesseract-ocr with a serverless Java application built for Azure Functions?如何将 tesseract-ocr 与为 Azure Functions 构建的无服务器 Java 应用程序捆绑在一起?
【发布时间】:2021-03-23 08:14:23
【问题描述】:

我正在添加 Apache Tika,用于从文档和图像中提取文本(使用 TikaOcr)到 Azure Functions 中基于 AppService 顶部的现有服务。现在,Apache Tika 需要将 tesseract 安装在本地机器上。为了克服这个问题,我使用 apt-get 设置(通过 ssh-ing)到服务器中,但是(据我了解)设置是在基础 AppService 层上执行的。结果,并发 OCR 命令的调用确实减慢了我的功能。由于没有 Tesseract 的官方二进制文件,我想知道以下是否可行:

  1. 将 Tesseract 与我的 Functions 应用程序捆绑在一起
  2. 使用 Tesseract 构建 docker 映像。
  3. 使用 tesseract 运行时映像 (tesseract-shadow/tesseract-ocr-re) 构建多容器 docker 应用

我已尝试使用带有以下 dockerfile 的 tesseract 构建 docker 映像(按照 here 的说明),但 Apache Tika 无法使用此执行 OCR。

ARG JAVA_VERSION=11

# This image additionally contains function core tools – useful when using custom extensions
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-core-tools AS installer-env
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env

RUN apt-get update && apt-get install -y tesseract-ocr

COPY . /src/functions-tika-extraction
RUN cd /src/functions-tika-extraction && \
    mkdir -p /home/site/wwwroot && \
    mvn clean package && \
    cd ./target/azure-functions/ && \
    cd $(ls -d */|head -n 1) && \
    cp -a . /home/site/wwwroot

# This image is ssh enabled
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
# This image isn't ssh enabled
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

我对 Docker 和 Azure 平台还很陌生,所以我可能在这里遗漏了一些东西,但是我怎样才能让我的 Azure Functions 使用 Docker 或任何其他方法与 Tesseract 一起工作?

【问题讨论】:

    标签: java docker azure-functions ocr apache-tika


    【解决方案1】:

    在阅读了 docker 文档并了解了一些关于 docker 的基础知识之后,我终于可以弄清楚 tesseract 实际上是安装在 Azure AppService 层之下的,它以某种方式不允许容器访问它。如果将 Tesseract 安装在最上层,则可以通过将 Tesseract 包含在 Dockerfile 的底部将其提供给 Azure Functions,如下所示:

    ARG JAVA_VERSION=11
    
    FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env
    
    # remove this line
    # RUN apt-get update && apt-get install -y tesseract-ocr
    
    COPY . /src/functions-tika-extraction
    RUN cd /src/functions-tika-extraction && \
        mkdir -p /home/site/wwwroot && \
        mvn clean package && \
        cd ./target/azure-functions/ && \
        cd $(ls -d */|head -n 1) && \
        cp -a . /home/site/wwwroot
    
    # This image is ssh enabled
    FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
    
    # add the line here
    RUN apt-get update && apt-get install -y tesseract-ocr
    
    ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
        AzureFunctionsJobHost__Logging__Console__IsEnabled=true
    
    COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
    

    虽然它确实满足了我将 tesseract-ocr 与 Azure Functions Java 应用程序捆绑的要求,但不幸的是,调用仍然很慢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 2013-03-16
      • 2011-11-02
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2018-12-19
      相关资源
      最近更新 更多