图片识别需要的包:import cv2
import argparse
opencv安装方法
pip install --upgrade setuptools pip install numpy Matplotlib pip install opencv-python
flask框架部署在服务器gunicorn -w 3 -b 127.0.0.1:8007 artbd_image_contrast:app
gunicorn安装
pip install gunicorn
运行工程项目
1.这里使用gunicorn 启动工程
gunicorn -D -w 3 -b 127.0.0.1:8000 application:app
2.这里说明一下:
- D 表示后台运行
- w 表示有3 个 工作线程(感觉有些类似 nginx 的 master-worker 模型)
- b 指定ip 和端口
- 这里采用本机访问, 主要是为了使用nginx 进行代理, 方便管理
- application 表存放 写着全局变量 app 的那个工程文件夹
- 在我们的这个工程中, 即包含 init.py 的那个文件
- app 为全局变量 (app = Flask(__name__)
)
tornado 代码,run.py:
- from tornado.wsgi import WSGIContainer
- from tornado.httpserver import HTTPServer
- from tornado.ioloop import IOLoop
- #导入flask项目
- from main import app
- http_server = HTTPServer(WSGIContainer(app))
- http_server.listen(5000)#对应flask的端口
- IOLoop.instance().start()
- #如果要开启多进程模式用下面的代码,不过仅在linux下
- # http_server = HTTPServer(WSGIContainer(app))
- # http_server.bind(8888)
- # http_server.start(0)
- # IOLoop.instance().start()
修改nginx配置文件,:
- server {
- listen 9900; #默认是80,我改成了9900
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root html;
- index index.html index.htm;
- proxy_pass http://localhost:5000; #添加这句,指向flask
- }