-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.py
54 lines (40 loc) · 1.73 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from flask import Flask,jsonify,request,render_template
from source.face_recognition import recognize_faces
from source.utils import draw_rectangles, read_image, prepare_image
from source.model_training import create_mlp_model
app = Flask(__name__)
app.config.from_object('config')
UPLOAD_FOLDER = os.path.basename('uploads')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def home():
return render_template('index.html')
@app.route('/recognize', methods=['POST'])
def detect():
file = request.files['image']
# Read image
image = read_image(file)
# Recognize faces
classifier_model_path = "models" + os.sep + "lotr_mlp_10c_recognizer.pickle"
label_encoder_path = "models" + os.sep + "lotr_mlp_10c_labelencoder.pickle"
faces = recognize_faces(image, classifier_model_path, label_encoder_path, detection_api_url=app.config["DETECTION_API_URL"])
return jsonify(recognitions = faces)
@app.route('/upload', methods=['POST'])
def upload():
file = request.files['image']
# Read image
image = read_image(file)
# Recognize faces
classifier_model_path = "models" + os.sep + "lotr_mlp_10c_recognizer.pickle"
label_encoder_path = "models" + os.sep + "lotr_mlp_10c_labelencoder.pickle"
faces = recognize_faces(image, classifier_model_path, label_encoder_path, detection_api_url=app.config["DETECTION_API_URL"])
# Draw detection rects
draw_rectangles(image, faces)
# Prepare image for html
to_send = prepare_image(image)
return render_template('index.html', face_recognized=len(faces)>0, num_faces=len(faces), image_to_show=to_send, init=True)
if __name__ == '__main__':
app.run(debug=True,
use_reloader=True,
port=4000)