【发布时间】:2019-03-16 07:25:20
【问题描述】:
我有
- takePhoto.py :从网络摄像头拍摄照片的 Python 脚本
- app.py 一个处理 POST 请求的 Flask 应用
如何通过 POST 请求将从 takePhoto.py 拍摄的图像发送到 Flask 应用程序?
takePhoto.py
import cv2
cap = cv2.VideoCapture(0)
r, f = cap.read()
if r == True:
cv2.imwrite("cheese.jpg", f)
# ---> Here I have the image and I want to send it to the Flask app
cap.release()
app.py
import os
from flask import Flask, render_template, request
app = Flask(__name__)
IMAGE_FOLDER = os.path.join('static', 'photos')
app.config['UPLOAD_FOLDER'] = IMAGE_FOLDER
@app.route('/')
def show_index():
return render_template("index.html")
@app.route('/uploadPicture', methods=['POST'])
def uploadPicture():
print("uploadPicture function triggered")
file = request.files['image']
complete_file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(complete_file_path)
return render_template("gallery.html", current_image = complete_file_path )
if __name__ == ("__main__"):
app.run()
【问题讨论】: