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, request, Response
20 from flask_cors import CORS
26 app.config['JSON_AS_ASCII'] = False
27 app.config['UPLOAD_PATH'] = '/usr/app/images/'
28 app.config['supports_credentials'] = True
29 app.config['CORS_SUPPORTS_CREDENTIALS'] = True
30 app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
31 ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
36 class shelf_inventry():
38 def __init__(self, url):
39 # self.video = cv2.VideoCapture(url)
42 # self.video.release()
49 store time series data in influx db
51 # TODO config, schema table, DB, fill data set
56 detect obj and count for self
60 @app.route('/v1/monitor/cameras', methods=['POST'])
62 camera_info = request.json
63 app.logger.info("Received message from ClientIP [" + request.remote_addr
64 + "] Operation [" + request.method + "]" +
65 " Resource [" + request.url + "]")
66 camera_info = {"name": camera_info["name"],
67 "rtspurl": camera_info["rtspurl"],
68 "location": camera_info["location"]}
69 # listOfCameras.append(camera_info)
70 return Response("success")
73 @app.route('/v1/monitor/cameras/<name>/<rtspurl>/<location>', methods=['GET'])
74 def get_camera(name, rtspurl, location):
76 register camera with location
78 app.logger.info("Received message from ClientIP [" + request.remote_addr
79 + "] Operation [" + request.method + "]" +
80 " Resource [" + request.url + "]")
81 # camera_info = {"name": name, "rtspurl": rtspurl, "location": location}
83 if "mp4" in camera_info["rtspurl"]:
84 # video_file = VideoFile(camera_info["rtspurl"])
85 # video_dict = {camera_info["name"]:video_file}
86 # listOfVideos.append(video_dict)
87 # return Response(video(video_file, camera_info["name"]),
88 # mimetype='multipart/x-mixed-replace; boundary=frame')
90 # video_file = VideoCamera(camera_info["rtspurl"])
91 # video_dict = {camera_info["name"]: video_file}
92 # listOfVideos.append(video_dict)
93 # return Response(video(video_file, camera_info["name"]),
94 # mimetype='multipart/x-mixed-replace; boundary=frame')
95 return Response("success")
99 @app.route('/v1/monitor/cameras/<camera_name>', methods=['DELETE'])
100 def delete_camera(camera_name):
101 app.logger.info("Received message from ClientIP [" + request.remote_addr
102 + "] Operation [" + request.method + "]" +
103 " Resource [" + request.url + "]")
105 for video1 in listOfVideos:
106 if camera_name in video1:
107 video_obj = video1[camera_name]
109 for camera in listOfCameras:
110 if camera_name == camera["name"]:
111 listOfCameras.remove(camera)
112 for msg in listOfMsgs:
113 if camera_name in msg["msg"]:
114 listOfMsgs.remove(msg)
115 return Response("success")
119 @app.route('/v1/monitor/cameras')
121 app.logger.info("Received message from ClientIP [" + request.remote_addr
122 + "] Operation [" + request.method + "]" +
123 " Resource [" + request.url + "]")
124 # return jsonify(listOfCameras)
125 return Response("success")
128 def start_server(handler):
129 app.logger.addHandler(handler)
130 if config.ssl_enabled:
131 context = (config.ssl_certfilepath, config.ssl_keyfilepath)
132 app.run(host=config.server_address, debug=True, ssl_context=context,
133 threaded=True, port=config.server_port)
135 app.run(host=config.server_address, debug=True, threaded=True,
136 port=config.server_port)