-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver_code.py
More file actions
57 lines (48 loc) · 1.34 KB
/
Copy pathserver_code.py
File metadata and controls
57 lines (48 loc) · 1.34 KB
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
55
56
import cv2 as cv
import numpy as np
#import requests
import simplejson as json
from flask import Flask, jsonify, request, render_template, send_from_directory, redirect
app = Flask(__name__)
#app.debug = True
faces = []
@app.route("/")
def main():
#return send_from_directory('','index.html')
#return app.send_static_file('index.html')
return redirect("/facerecognition", code=302)
@app.route("/clear")
def clear():
global faces
faces = []
return redirect("/facerecognition", code=302)
@app.route("/faces/<path:filename>")
def returnFace(filename):
print filename
return send_from_directory('./faces/',filename)
@app.route("/facerecognition")
def facerecognition():
global faces
paths = []
i = 0
for face in faces:
face = np.array(face)
#face = cv.imdecode(face,1)
filename = "./faces/" + str(i)+".jpg"
cv.imwrite(filename,face)
paths.append(filename)
i += 1
return render_template("facerecognition.html", faces=paths)
@app.route("/upload",methods=["POST"])
def test():
#pprint(vars(request))
#print json.loads(request.form['img'])
faces.append(json.loads(request.form['img']))
#faces.append( request.form['img'] )
#return "Testing!"
try:
return jsonify(dict(ok=True))
except:
pass
if __name__ == '__main__':
app.run()