-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
61 lines (48 loc) · 1.84 KB
/
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
54
55
56
57
58
59
60
61
from flask import Flask, request, jsonify
import os
from werkzeug.utils import secure_filename
from binascii import a2b_base64
import registerFromImage
import numpy as np
import time
import pickle
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
@app.route("/")
def hello():
return "<meta http-equiv=refresh content=\"0; URL='/static/index.html'\" />"
@app.route('/imageupload/<float:name>', methods=['POST'])
def imageupload(name):
filename = secure_filename(str(name) + ".png")
out = open(os.path.join("image_uploads", filename), "wb")
image_enc = request.form["image"]
header = "data:image/png;base64,"
assert(image_enc[:len(header)] == header)
print(len(image_enc))
if len(image_enc) < 9000000:
image_enc = image_enc[len(header):]
out.write(a2b_base64(image_enc))
out.close()
return ''
@app.route('/linestotransform', methods=["POST"])
def linestotransform():
json = request.get_json()
#print(json)
imu = json["imu"]
if imu["alpha"]:
roll, pitch, yaw = [imu[n] * 3.1415 / 180 for n in ("gamma", "beta", "alpha")]
vertical_scale = json['shape'][1] / json['shape'][0]
error, vector = registerFromImage.registerFromLines(np.array([[l[:2]] for l in json['lines']]),
attitude = imu["alpha"] and np.array([[roll], [yaw], [pitch]]),
vertical_factor=vertical_scale,
graph=False,
focalLength = (4/3) * 117)
return jsonify({'error': error, "vector": [v for v in vector]})
@app.route('/uploadtrack', methods=["POST"])
def uploadtrack():
json = request.get_json()
pickle.dump(json, open("trajectory/" + "S"+ ".pickle", "wb"))
pickle.dump(json, open("trajectory/" + str(time.time()) + ".pickle", "wb"))
return ""
if __name__ == "__main__":
app.run(host="0.0.0.0", port=443, ssl_context=('cert.pem', 'key.pem'))