Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import face_recognition
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
@app.route('/recognize', methods=['POST'])
|
| 9 |
+
def recognize():
|
| 10 |
+
file = request.files['image']
|
| 11 |
+
np_img = np.frombuffer(file.read(), np.uint8)
|
| 12 |
+
img = cv2.imdecode(np_img, cv2.IMREAD_COLOR)
|
| 13 |
+
|
| 14 |
+
face_locations = face_recognition.face_locations(img)
|
| 15 |
+
face_encodings = face_recognition.face_encodings(img, face_locations)
|
| 16 |
+
|
| 17 |
+
response = {
|
| 18 |
+
"faces_detected": len(face_locations),
|
| 19 |
+
"face_locations": face_locations
|
| 20 |
+
}
|
| 21 |
+
return jsonify(response)
|
| 22 |
+
|
| 23 |
+
if __name__ == '__main__':
|
| 24 |
+
app.run(host='0.0.0.0', port=5000)
|