I've a desktop application to detect faces written in python script, using opencv and numpy.
i want to put these python files into flask and run it, would it run without problems? like
import numpy as np
from flask import Flask
app = Flask(__name__)
## define my functions here
return 'Hello World!'
if __name__ == '__main__':
#call the functions here
Yes it would work, one thing you should know is if you do like below, the HTTP request won't return until after the processing is done e.g.
@app.route('/webcam') def webcam_capture(): """ Returns a picture snapshot from the webcam """ image = cv2... # call a function to get an image response = make_response(image) # make an HTTP response with the image response.headers['Content-Type'] = 'image/jpeg' response.headers['Content-Disposition'] = 'attachment; filename=img.jpg' return response
Otherwise, if you put in the main function like below
if __name__ == '__main__': # <-- No need to put things here, unless you want them to run before # the app is ran (e.g. you need to initialize something) app.run()
Then your flask app won't start until the init/processing is done.