-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (30 loc) · 827 Bytes
/
app.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
import traceback
import cv2
from flask import request, jsonify, Response
import flask
import numpy as np
from flask_cors import CORS, cross_origin
from main import pipeline
app = flask.Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/')
def hello_world(): # put application's code here
return 'Hello World!'
@app.post('/cv')
@cross_origin()
def intake_image():
try:
file = request.files['file']
frame = cv2.imdecode(np.frombuffer(file.read(), np.uint8), cv2.IMREAD_COLOR)
res = pipeline(frame)
return jsonify(res)
except Exception as e:
msg = traceback.format_exc()
print(msg)
return Response(
str(msg),
400
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)