-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask.py
46 lines (35 loc) · 1.1 KB
/
flask.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
#-*-coding:utf-8 -*-
from flask import Flask
from flask import request, json
import json
from PIL import Image
from download import download_image
from iinit import det
PAGE = '''<!doctype html>
<title>Object Detection</title>
<h1>yolo object detection</h1>
<form action="" method=post enctype=multipart/form-data>
<p>
<label for="image">image</label>
<input type=file name=file required>
<input type=submit value=detect>
</form>
'''
app = Flask('Detection')
@app.route('/', methods=['GET'])
def index():
return redirect(url_for('detector'))
@app.route('/detector', methods=['GET', 'POST'])
def detector():
if request.method !='POST':
return PAGE
img = request.files['file']
data = img.read()
arr = np.frombuffer(data, dtype=np.uint8)
img = cv2.imdecode(arr, cv2.IMREAD_COLOR)
bboxes = detection(img=img)
bboxes = bboxes.reshape(-1, 8).tolist()
# print('inference time: ', time.time()-tic)
return jsonify(msg='success', data={'bboxes': bboxes})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)