2 # Copyright 2020 Huawei Technologies Co., Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from flask_sslify import SSLify
19 from flask import Flask, Response
20 from flask_cors import CORS
24 def __init__(self, model_name):
25 self.model = 'model_info/MobileNetSSD_deploy.caffemodel'
26 self.model_name = model_name
27 self.prototxt = 'model_info/MobileNetSSD_deploy.prototxt'
28 self.confidenceLevel = 80
33 def get_prototxt(self):
36 def get_model_name(self):
37 return self.model_name
39 def set_confidence_level(self, confidenceLevel):
40 self.confidenceLevel = confidenceLevel
42 def get_confidence_level(self):
43 return self.confidenceLevel
45 def update_model(self, model, prototxt, model_name):
46 self.prototxt = prototxt
48 self.model_name = model_name
52 classNames = {0: 'background',
53 1: 'aeroplane', 2: 'bicycle', 3: 'bird', 4: 'boat',
54 5: 'bottle', 6: 'bus', 7: 'car', 8: 'cat', 9: 'chair',
55 10: 'cow', 11: 'diningtable', 12: 'dog', 13: 'horse',
56 14: 'motorbike', 15: 'person', 16: 'pottedplant',
57 17: 'sheep', 18: 'sofa', 19: 'train', 20: 'tvmonitor'}
62 app.config['JSON_AS_ASCII'] = False
63 app.config['UPLOAD_PATH'] = '/usr/app/images/'
64 app.config['supports_credentials'] = True
65 app.config['CORS_SUPPORTS_CREDENTIALS'] = True
66 app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
67 ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
72 def allowed_file(filename):
73 return '.' in filename and filename.rsplit('.', 1)[1].lower()\
77 @app.route('/mep/v1/obj_detection/uploadModel', methods=['POST'])
84 return Response("success")
87 @app.route('/mep/v1/obj_detection/confidencelevel', methods=['POST'])
88 def setConfidenceLevel():
90 Trigger the video_feed() function on opening "0.0.0.0:5000/video_feed" URL
94 return Response("success")
97 @app.route('/mep/v1/obj_detection/detect', methods=['GET'])
100 Trigger the Obj detection on input frame/image
102 :return: imposed frame, count, Obj type, time taken by detection
104 return Response("success")
107 def start_server(handler):
108 app.logger.addHandler(handler)
109 if config.ssl_enabled:
110 context = (config.ssl_certfilepath, config.ssl_keyfilepath)
111 app.run(host=config.server_address, debug=True, ssl_context=context,
112 threaded=True, port=config.server_port)
114 app.run(host=config.server_address, debug=True, threaded=True,
115 port=config.server_port)