parent
c110f1f668
commit
a7dc32b970
|
|
@ -3,18 +3,21 @@
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"label": "cam1",
|
"label": "cam1",
|
||||||
"ip": "http://208.72.70.171:80/mjpg/video.mjpg",
|
"ip": "http://208.72.70.171:80/mjpg/video.mjpg",
|
||||||
|
"client_id": 0,
|
||||||
"status": true
|
"status": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"label": "cam2",
|
"label": "cam2",
|
||||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||||
|
"client_id": 1,
|
||||||
"status": false
|
"status": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"label": "cam3",
|
"label": "cam3",
|
||||||
"ip": "http://62.99.80.154:81/mjpg/video.mjpg",
|
"ip": "http://62.99.80.154:81/mjpg/video.mjpg",
|
||||||
|
"client_id": 2,
|
||||||
"status": true
|
"status": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
FROM python:3.7
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install -y gcc libevent-dev python-dev
|
||||||
|
|
||||||
|
COPY ./requirements.txt /
|
||||||
|
RUN pip install -r /requirements.txt
|
||||||
|
|
||||||
|
COPY ./ /app
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app"]
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,117 @@
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import requests
|
||||||
|
import detector as dt
|
||||||
|
import cv2
|
||||||
|
import _thread
|
||||||
|
from flask import Flask, jsonify, Response
|
||||||
|
|
||||||
|
######### ###########
|
||||||
|
### Init ###
|
||||||
|
######### ###########
|
||||||
|
|
||||||
|
application = Flask(__name__)
|
||||||
|
|
||||||
|
clients = []
|
||||||
|
cams = []
|
||||||
|
with open("./server/clients.json", 'r', encoding='utf-8') as f:
|
||||||
|
array = f.read()
|
||||||
|
clients = json.loads(array)
|
||||||
|
|
||||||
|
with open("./server/cams.json", 'r', encoding='utf-8') as f:
|
||||||
|
array = f.read()
|
||||||
|
cams = json.loads(array)
|
||||||
|
|
||||||
|
class VideoCamera(object):
|
||||||
|
"""Video stream object"""
|
||||||
|
def __init__(self, url):
|
||||||
|
self.video = cv2.VideoCapture(url)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.video.release()
|
||||||
|
|
||||||
|
def get_frame(self):
|
||||||
|
success, image = self.video.read()
|
||||||
|
ret, jpeg = cv2.imencode('.jpg', image)
|
||||||
|
return jpeg.tobytes()
|
||||||
|
|
||||||
|
def gen(camera):
|
||||||
|
"""Video streaming generator function."""
|
||||||
|
while True:
|
||||||
|
frame = camera.get_frame()
|
||||||
|
yield (b'--frame\r\n'
|
||||||
|
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
|
||||||
|
|
||||||
|
######### ###########
|
||||||
|
### Core ###
|
||||||
|
######### ###########
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for cam in cams:
|
||||||
|
t = 1 # seconds a person can leave the room for
|
||||||
|
t0 = time.time()
|
||||||
|
time.clock()
|
||||||
|
elapsed = 0
|
||||||
|
stream = cam["ip"]
|
||||||
|
detector = dt.Detector(stream)
|
||||||
|
music_playing = client_ip = clients[cam["client_id"]]["status"]
|
||||||
|
client_ip = "http://" + clients[cam["client_id"]]["ip"]
|
||||||
|
|
||||||
|
while True:
|
||||||
|
elapsed = time.time() - t0
|
||||||
|
if elapsed > t and music_playing:
|
||||||
|
r = requests.get(client_ip + "/stop")
|
||||||
|
if r.status_code == 200:
|
||||||
|
clients[cam["client_id"]]["status"] = False
|
||||||
|
tmp = time.time()
|
||||||
|
img = detector.detect()
|
||||||
|
print(time.time()-tmp)
|
||||||
|
if img is not None and not music_playing:
|
||||||
|
r = requests.get(client_ip + "/play")
|
||||||
|
if r.status_code == 200:
|
||||||
|
clients[cam["client_id"]]["status"] = True
|
||||||
|
t0 = time.time()
|
||||||
|
# TODO noch nicht sicher wie ich das verarbeirtete Bild ausgebe
|
||||||
|
#cv2.imshow("preview", img)
|
||||||
|
#cv2.waitKey(1)
|
||||||
|
|
||||||
|
######### ###########
|
||||||
|
### Routes ###
|
||||||
|
######### ###########
|
||||||
|
|
||||||
|
@application.route('/client/')
|
||||||
|
def client_list():
|
||||||
|
json = clients
|
||||||
|
return jsonify(json)
|
||||||
|
|
||||||
|
@application.route('/client/<num>/info')
|
||||||
|
def client_info(num):
|
||||||
|
json = clients[int(num)]
|
||||||
|
return jsonify(json)
|
||||||
|
|
||||||
|
@application.route('/cam/')
|
||||||
|
def cam_list():
|
||||||
|
json = cams
|
||||||
|
return jsonify(json)
|
||||||
|
|
||||||
|
@application.route('/cam/<num>/info')
|
||||||
|
def cam_info(num):
|
||||||
|
json = cams[int(num)]
|
||||||
|
return jsonify(json)
|
||||||
|
|
||||||
|
@application.route('/cam/<num>/stream')
|
||||||
|
def cam_stream(num):
|
||||||
|
return Response(gen(VideoCamera(cams[int(num)]["ip"])),
|
||||||
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||||
|
|
||||||
|
|
||||||
|
######### ###########
|
||||||
|
### Start ###
|
||||||
|
######### ###########
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
_thread.start_new_thread(main, () )
|
||||||
|
|
||||||
|
|
||||||
|
application.run(host='127.0.0.1', port=80)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"label": "cam1",
|
||||||
|
"ip": "http://208.72.70.171:80/mjpg/video.mjpg",
|
||||||
|
"client_id": 0,
|
||||||
|
"status": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"label": "cam2",
|
||||||
|
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||||
|
"client_id": 1,
|
||||||
|
"status": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"label": "cam3",
|
||||||
|
"ip": "http://62.99.80.154:81/mjpg/video.mjpg",
|
||||||
|
"client_id": 2,
|
||||||
|
"status": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"label": "name1",
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"status": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"label": "name2",
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"status": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"label": "name3",
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"status": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -60,7 +60,7 @@ class DetectorAPI:
|
||||||
|
|
||||||
class Detector:
|
class Detector:
|
||||||
def __init__(self, stream):
|
def __init__(self, stream):
|
||||||
self.model_path = "./model.pb"
|
self.model_path = "./server/model.pb"
|
||||||
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
||||||
self.threshold = 0.8
|
self.threshold = 0.8
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
requests
|
||||||
|
flask
|
||||||
|
gunicorn
|
||||||
|
opencv-python
|
||||||
Loading…
Reference in New Issue