I have
- takePhoto.py : a Python script that takes a picture from the webcam
- app.py a Flask app that handles POST request
How can I send the image taken from takePhoto.py to the Flask app with a POST request?
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()