Heroku中的OpenCV Python Web应用程序 [英] Python web application with OpenCV in Heroku

查看:139
本文介绍了Heroku中的OpenCV Python Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个在其后端使用OpenCV的Web应用程序。我已经在Ubuntu上构建了应用程序(并且我也在Windows上尝试了它),并且它工作正常。目前,我正在尝试将OpenCV配置为在Heroku上运行。由于OpenCV不可能使用pip加载,所以我阅读了有关使用提供自定义服务器环境的heroku buildpacks。

以下是我尝试测试OpenCV中的两个buildpacks:


  1. 我用Flask构建简单的Web服务器,尝试导入OpenCV:

     #hello.py 
    从烧瓶导入烧瓶导入烧瓶

    $ b app =烧瓶(__ name__)
    @ app.route(/)
    def hello():
    text =''
    尝试:
    导入cv2
    text ='success'
    除外:
    text ='fail'
    传递
    返回文本+'加载openCV'

    if __name__ ==__main__:
    port = int(os.environ.get(PORT,5000))
    app.run(host ='0.0.0.0',port = port)

    上面的代码在加载OpenCV时应该返回成功或失败。

  2. 然后我配置了Heroku使用(heroku多buildpac k)运行以下命令:

    heroku buildpacks:set https://github.com/ddollar/heroku-buildpack-multi

  3. 在.buildpacks文件中(即需要多buildpack)我把 https://github.com/heroku/heroku-buildpack- python https://github.com/slobdell/heroku- buildpack-python-opencv-scipy buildpacks。

    第一个用于编译python应用程序和通过<$安装其他模块(例如Flask) c $ c> pip。第二个buildpack是应该加载OpenCV的那个。




毕竟,整个应用程序无法正常工作!



我在Heroku的(Application Error)页面中看到以下scr eenshot:

我尝试使用其他buildpack( https://github.com/diogojc/我的问题是:

有什么不对的地方在我做的步骤?

我应该如何在我的应用程序中调用(或使用)OpenCV在heroku中?我应该使用 import 语句或一些其他的命令?

我可以按照如下方式安装: $ b

  • cd / path / to / your / dir&& git init


  • heroku创建MYAPP p>


  • heroku配置:添加BUILDPACK_URL = https://github.com/ddollar/heroku-buildpack-multi.git --app MYAPP


  • 创建 .buildpacks ,如下所示: b

      https://github.com/heroku/heroku-buildpack-python 
    https://github.com/diogojc/heroku-buildpack- python-opencv-scipy#cedar14


  • git add。 &安培;&安培; git commit -m'MESSAGE'&& git push heroku master



  • I am building a web application that uses OpenCV in its back-end. I have built the application on Ubuntu (and I tried it on Windows, too) and it works fine. Currently, I am trying to configure OpenCV to work on Heroku. As OpenCV is not possible to be loaded using pip, I read about using heroku buildpacks which provide customization for the server environment.

    The following is my attempt to test two of OpenCV buildpacks:

    1. I build simple web server with Flask that tries to import OpenCV:

      #hello.py
      import os 
      from flask import Flask
      
      app = Flask(__name__)  
      @app.route("/")
      def hello():
          text = ''
          try:
              import cv2
              text = 'success' 
          except:
              text = 'fail'
              pass
          return text + ' to load openCV'
      
      if __name__ == "__main__":
          port = int(os.environ.get("PORT", 5000))
          app.run(host='0.0.0.0', port=port)
      

      The above code should return either success or fail in loading OpenCV.

    2. Then I configured Heroku to use (heroku multi buildpack) by running the following command:

      heroku buildpacks:set https://github.com/ddollar/heroku-buildpack-multi

    3. In the .buildpacks file (that is required by multi buildpack) I put the https://github.com/heroku/heroku-buildpack-python and https://github.com/slobdell/heroku-buildpack-python-opencv-scipy buildpacks.

      The first one is for compiling a python application and for installing other modules (e.g., Flask) through pip. The second buildpack is the one that is supposed to load OpenCV.

    After all, the whole application did not work!

    I got (Application Error) page in Heroku as following screenshot:

    I tried to use other buildpack (https://github.com/diogojc/heroku-buildpack-python-opencv-scipy) but I got the same result.

    My questions are:
    What is wrong in the steps I did?
    How should I call (or use) OpenCV within my application in heroku?
    Should I use import statement or some other commands?

    解决方案

    I could install by doing as follows:

    1. cd /path/to/your/dir && git init

    2. heroku create MYAPP (start from scratch)

    3. heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git --app MYAPP

    4. create .buildpacks as follows:

      https://github.com/heroku/heroku-buildpack-python
      https://github.com/diogojc/heroku-buildpack-python-opencv-scipy#cedar14
      

    5. git add . && git commit -m 'MESSAGE' && git push heroku master

    这篇关于Heroku中的OpenCV Python Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆