-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
31 lines (24 loc) · 820 Bytes
/
run.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
from flask import Flask, request, Response
import jsonpickle
import numpy as np
import cv2
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/stopzone', methods=['POST'])
def upload_file():
r = request
# convert string of image data to uint8
nparr = np.fromstring(r.data, np.uint8)
# decode image
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
# do some fancy processing here....
# build a response dict to send back to client
response = {'stopzone': 'stopzone. size={}x{}'.format(img.shape[1], img.shape[0])
}
# encode response using jsonpickle
response_pickled = jsonpickle.encode(response)
return Response(response=response_pickled, status=200, mimetype="application/json")
if __name__ == '__main__':
app.run()