client zeug

This commit is contained in:
Patrice 2019-06-10 13:54:58 +02:00
parent f2553b7067
commit 6ed5ff1046
6 changed files with 36 additions and 50 deletions

View File

@ -2,47 +2,34 @@ from flask import Flask, request
import os import os
import simpleaudio as sa import simpleaudio as sa
#----------------------------------------------------------------------------#
# App Config.
#----------------------------------------------------------------------------#
app = Flask(__name__) app = Flask(__name__)
#----------------------------------------------------------------------------#
# Controllers.
#----------------------------------------------------------------------------#
p = None p = None
w = None w = sa.WaveObject.from_wave_file("./rave.wav")
playing = False playing = False
@app.route('/play') @app.route('/play')
def index(): def index():
global p, playing global playing, p, w
playing = True
print("yes")
p = w.play()
if playing: if playing:
return 406 return 406
if not playing: else:
playing = True
p = w.play()
return 200 return 200
@app.route('/stop') @app.route('/stop')
def test(): def test():
global p, playing global playing, p
playing = False
p.stop()
if playing: if playing:
return 200 return 200
if not playing: else:
playing = False
p.stop()
return 406 return 406
if __name__ == '__main__':
port = int(os.environ.get('PORT', 80))
global p
global w
w = sa.WaveObject.from_wave_file("./rave.wav")
port = int(os.environ.get('PORT', 81))
app.run(host='0.0.0.0', port=port) app.run(host='0.0.0.0', port=port)

Binary file not shown.

View File

@ -5,8 +5,7 @@ import requests
import detector as dt import detector as dt
import cv2 import cv2
import _thread import _thread
import copy from flask import Flask, jsonify, Response, send_file
from flask import Flask, jsonify, Response, make_response, send_file
######### ########### ######### ###########
### Init ### ### Init ###
@ -49,12 +48,13 @@ def gen(camera):
def main(): def main():
detector = dt.Detector() detector = dt.Detector()
while True:
for cam in cams:
t = 1 # seconds a person can leave the room for t = 1 # seconds a person can leave the room for
t0 = time.time() t0 = time.time()
time.clock()
elapsed = 0 elapsed = 0
while True:
for cam in cams:
stream = cam["ip"] stream = cam["ip"]
clientStatus = clients[cam["client_id"]]["status"] clientStatus = clients[cam["client_id"]]["status"]
@ -63,8 +63,8 @@ def main():
elapsed = time.time() - t0 elapsed = time.time() - t0
if elapsed > t and clientStatus: if elapsed > t and clientStatus:
try: try:
#r = requests.get(clientIp + "/stop") r = requests.get(clientIp + "/stop")
#if r.status_code == 200: if r.status_code == 200:
clients[cam["client_id"]]["status"] = False clients[cam["client_id"]]["status"] = False
cam["status"] = False cam["status"] = False
except: except:
@ -77,8 +77,8 @@ def main():
if result and not clientStatus: if result and not clientStatus:
try: try:
#r = requests.get(clientIp + "/play") r = requests.get(clientIp + "/play")
#if r.status_code == 200: if r.status_code == 200:
clients[cam["client_id"]]["status"] = True clients[cam["client_id"]]["status"] = True
cam["status"] = True cam["status"] = True
t0 = time.time() t0 = time.time()

View File

@ -4,7 +4,7 @@
"label": "cam1", "label": "cam1",
"ip": "http://89.29.108.38:80/mjpg/video.mjpg", "ip": "http://89.29.108.38:80/mjpg/video.mjpg",
"client_id": 0, "client_id": 0,
"status": true, "status": false,
"x":0.2, "x":0.2,
"y":0.8, "y":0.8,
"angle": 130 "angle": 130
@ -24,7 +24,7 @@
"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, "client_id": 2,
"status": true, "status": false,
"x":0.9, "x":0.9,
"y":0.1, "y":0.1,
"angle": 270 "angle": 270

View File

@ -2,15 +2,15 @@
{ {
"id": 0, "id": 0,
"label": "name1", "label": "name1",
"ip": "http://127.0.0.2", "ip": "",
"status": true, "status": false,
"x":0.11, "x":0.11,
"y":0.8 "y":0.8
}, },
{ {
"id": 1, "id": 1,
"label": "name2", "label": "name2",
"ip": "http://127.0.0.2", "ip": "http://127.0.0.1:81",
"status": false, "status": false,
"x":0.3, "x":0.3,
"y":0.3 "y":0.3
@ -18,8 +18,8 @@
{ {
"id": 2, "id": 2,
"label": "name3", "label": "name3",
"ip": "http://127.0.0.2", "ip": "",
"status": true, "status": false,
"x":0.5, "x":0.5,
"y":0.6 "y":0.6
} }

View File

@ -66,6 +66,7 @@ class Detector:
def detect(self, stream): def detect(self, stream):
cap = cv2.VideoCapture(stream) cap = cv2.VideoCapture(stream)
img = None
r, img = cap.read() r, img = cap.read()
if img is None: if img is None:
return img return img
@ -73,8 +74,6 @@ class Detector:
boxes, scores, classes, num = self.odapi.process_frame(img) boxes, scores, classes, num = self.odapi.process_frame(img)
# Visualization of the results of a detection.
for i in range(len(boxes)): for i in range(len(boxes)):
# Class 1 represents human # Class 1 represents human
if classes[i] == 1: if classes[i] == 1:
@ -84,7 +83,7 @@ class Detector:
return img, True return img, True
else: else:
return img, False return img, False
# cv2.imshow("preeview", img) # cv2.destroyWindow("preview")
#def __del__(self): #def __del__(self):