-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeature_server.py
53 lines (44 loc) · 1.6 KB
/
feature_server.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
from flask import Flask, request, jsonify, abort
import numpy as np
import cv2
from scipy.misc import toimage
from cena.recognition import FaceRecognizer
from cena.utils import decode_image, encode_image
from cena.settings import DEV, ANNOTATE_FRAME
RECOGNIZER = FaceRecognizer()
app = Flask(__name__)
@app.route('/recognize', methods=['POST'])
def recognize():
if not request.json:
abort(400)
if 'frame' not in request.json:
abort(400)
if 'list_o_faces' not in request.json:
abort(400)
if 'shape' not in request.json:
abort(400)
# frame = cv2.imdecode(np.array(request.json['frame']), None)
# frame = np.array(request.json['frame'])
# frame = frame.astype('uint8')
# frame = toimage(np.array(request.json['frame']))
# frame = cv2.(np.array(request.json['frame']))
# print(frame[0][0].dtype)
encoded_frame = request.json['frame']
shape = request.json['shape']
return_frame = request.json.get('return_frame', False)
frame = decode_image(encoded_frame, shape)
list_o_faces = request.json['list_o_faces']
frame, people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)
# if ANNOTATE_FRAME:
# frame, people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)
# else:
# people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)
response = {
'people_list': people_list,
'time': time
}
if return_frame:
response.update({'frame': encode_image(frame)})
return jsonify(response)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)