Python 带有 tesseract 的应用程序不能在 Bluemix 上运行

Python app with tesseract does not work on Bluemix

我有一个 python 应用程序,它使用 tesseract 检测扫描图像中的复选框,在我的本地机器上工作得很好,但是当我将我的代码与 python-tesseract 一起推送到 Bluemix 时buildpack 无法生成输出文件,这意味着未在 Bluemix 上检测到 tesseract。

这是我的 manifest.yml:

applications:
- path: .
memory: 512M
instances: 1
domain: mybluemix.net
name: edge-noise-detector-bluemix
host: edge-noise-detector-bluemix
disk_quota: 1024M
buildpack: https://github.com/LeoKotschenreuther/python-tesseract-buildpack.git

这是我的 requirements.txt:

Flask
numpy
Pillow==4.1.1
pycparser
pyOpenSSL
pyparsing
pytesseract
python-dateutil
python-swiftclient
pytz
PyWavelets
scikit-image
scipy
requests
matplotlib==1.4.3
opencv-python
cf_deployment_tracker
tesseract

这是来自 Bluemix 的日志:

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "server.py", line 217, in predict_square_checkboxes
    ImgOcr = image_hocr_class.ocr_hocr('temporary.png')
  File "/home/vcap/app/src/image_hocr_class.py", line 39, in __init__
    self.HTMLTree = xml.etree.ElementTree.parse(self.HOCRFileName).getroot()
  File "/app/.heroku/python/lib/python3.6/xml/etree/ElementTree.py", line 1196, in parse
    tree.parse(source, parser)
  File "/app/.heroku/python/lib/python3.6/xml/etree/ElementTree.py", line 586, in parse
    source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'images/8e297b93a39f1e08a490f72c8db53bf0.hocr'

这通常发生在 pytesseract 无法定位 tesseract 的路径时。不确定如何在 Bluemix 上完成这项工作。 有没有人在 Bluemix 上使用 tesseract python?请帮忙。

IBM Cloud 为您提供了 运行 应用程序的多种可能性。 Cloud Foundry Runtimes 就是其中之一,但在您的情况下似乎不太合适。每当您有需要安装的依赖项时,您都需要创建自定义构建包,这可能是一项相当复杂的任务。 (https://docs.cloudfoundry.org/buildpacks/custom.html) 听说过 Docker/Kubernetes 吗?如果您有许多应用程序依赖项(如您的案例中的 tesseract),我建议您创建一个 Kubernetes 环境来构建您的应用程序! 查看这些资源:https://hub.docker.com/r/tesseractshadow/tesseract4re/ https://console.bluemix.net/docs/containers/container_index.html#container_index