parent
a1aa2847e1
commit
98a456847b
|
|
@ -50,7 +50,7 @@ namespace FrontEnd
|
|||
|
||||
static Communicator()
|
||||
{
|
||||
client.BaseAddress = new Uri("http://ui.askill.science:8003/");
|
||||
client.BaseAddress = new Uri("http://ui.askill.science:5000/");
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"id": 0,
|
||||
"label": "cam1",
|
||||
"ip": "http://208.72.70.171:80/mjpg/video.mjpg",
|
||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||
"client_id": 0,
|
||||
"status": true,
|
||||
"x":0.2,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"id": 0,
|
||||
"label": "name1",
|
||||
"ip": "127.0.0.1",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": true,
|
||||
"x":0.11,
|
||||
"y":0.8
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
{
|
||||
"id": 1,
|
||||
"label": "name2",
|
||||
"ip": "127.0.0.1",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": false,
|
||||
"x":0.3,
|
||||
"y":0.3
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
{
|
||||
"id": 2,
|
||||
"label": "name3",
|
||||
"ip": "127.0.0.1",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": true,
|
||||
"x":0.5,
|
||||
"y":0.6
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,10 +1,12 @@
|
|||
import io
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
import detector as dt
|
||||
import cv2
|
||||
import _thread
|
||||
from flask import Flask, jsonify, Response
|
||||
import copy
|
||||
from flask import Flask, jsonify, Response, make_response, send_file
|
||||
|
||||
######### ###########
|
||||
### Init ###
|
||||
|
|
@ -14,13 +16,12 @@ application = Flask(__name__)
|
|||
|
||||
clients = []
|
||||
cams = []
|
||||
with open("./server/clients.json", 'r', encoding='utf-8') as f:
|
||||
array = f.read()
|
||||
clients = json.loads(array)
|
||||
lastImages = list(range(0,4))
|
||||
with open("./server/clients.json", 'r', encoding='utf-8') as f:
|
||||
clients = json.loads(f.read())
|
||||
|
||||
with open("./server/cams.json", 'r', encoding='utf-8') as f:
|
||||
array = f.read()
|
||||
cams = json.loads(array)
|
||||
with open("./server/cams.json", 'r', encoding='utf-8') as f:
|
||||
cams = json.loads(f.read())
|
||||
|
||||
class VideoCamera(object):
|
||||
"""Video stream object"""
|
||||
|
|
@ -55,26 +56,34 @@ def main():
|
|||
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"]
|
||||
clientStatus = clients[cam["client_id"]]["status"]
|
||||
clientIp = clients[cam["client_id"]]["ip"]
|
||||
|
||||
|
||||
elapsed = time.time() - t0
|
||||
if elapsed > t and music_playing:
|
||||
r = requests.get(client_ip + "/stop")
|
||||
if r.status_code == 200:
|
||||
if elapsed > t and clientStatus:
|
||||
try:
|
||||
#r = requests.get(clientIp + "/stop")
|
||||
#if r.status_code == 200:
|
||||
clients[cam["client_id"]]["status"] = False
|
||||
cam["status"] = False
|
||||
except:
|
||||
print("request error")
|
||||
|
||||
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:
|
||||
img, result = detector.detect()
|
||||
print(cam["client_id"], result, time.time()-tmp)
|
||||
lastImages[cam["id"]] = img
|
||||
|
||||
if result and not clientStatus:
|
||||
try:
|
||||
#r = requests.get(clientIp + "/play")
|
||||
#if r.status_code == 200:
|
||||
clients[cam["client_id"]]["status"] = True
|
||||
cam["status"] = True
|
||||
t0 = time.time()
|
||||
# TODO noch nicht sicher wie ich das verarbeirtete Bild ausgebe
|
||||
#cv2.imshow("preview", img)
|
||||
#cv2.waitKey(1)
|
||||
except:
|
||||
print("request error")
|
||||
|
||||
|
||||
######### ###########
|
||||
### Routes ###
|
||||
|
|
@ -82,28 +91,28 @@ def main():
|
|||
|
||||
@application.route('/client/')
|
||||
def client_list():
|
||||
json = clients
|
||||
return jsonify(json)
|
||||
return jsonify(clients)
|
||||
|
||||
@application.route('/client/<num>/info')
|
||||
def client_info(num):
|
||||
json = clients[int(num)]
|
||||
return jsonify(json)
|
||||
return jsonify(clients[int(num)])
|
||||
|
||||
@application.route('/cam/')
|
||||
def cam_list():
|
||||
json = cams
|
||||
return jsonify(json)
|
||||
return jsonify(cams)
|
||||
|
||||
@application.route('/cam/<num>/info')
|
||||
def cam_info(num):
|
||||
json = cams[int(num)]
|
||||
return jsonify(json)
|
||||
return jsonify(cams[int(num)])
|
||||
|
||||
@application.route('/cam/<num>/stream')
|
||||
def cam_stream(num):
|
||||
return Response(gen(VideoCamera(cams[int(num)]["ip"])),
|
||||
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
return Response(gen(VideoCamera(cams[int(num)]["ip"])), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
@application.route('/cam/<num>/processed')
|
||||
def cam_stream_processed(num):
|
||||
frame = cv2.imencode('.jpg', lastImages[int(num)])[1]
|
||||
return send_file(io.BytesIO(frame), mimetype='image/jpeg')
|
||||
|
||||
|
||||
######### ###########
|
||||
|
|
@ -114,5 +123,4 @@ if __name__ == '__main__':
|
|||
|
||||
_thread.start_new_thread(main, () )
|
||||
|
||||
|
||||
application.run(host='127.0.0.1', port=80, threaded=True)
|
||||
application.run(host='0.0.0.0', port=5000, threaded=True)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,32 @@
|
|||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
{
|
||||
"id": 0,
|
||||
"label": "cam1",
|
||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||
"client_id": 0,
|
||||
"status": true,
|
||||
"x":0.2,
|
||||
"y":0.8,
|
||||
"angle": 130
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"label": "cam2",
|
||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||
"client_id": 1,
|
||||
"status": false,
|
||||
"x":0.4,
|
||||
"y":0.2,
|
||||
"angle": 190
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"label": "cam3",
|
||||
"ip": "http://62.99.80.154:81/mjpg/video.mjpg",
|
||||
"client_id": 2,
|
||||
"status": true,
|
||||
"x":0.9,
|
||||
"y":0.1,
|
||||
"angle": 270
|
||||
}
|
||||
]
|
||||
|
|
@ -1,20 +1,26 @@
|
|||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
{
|
||||
"id": 0,
|
||||
"label": "name1",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": true,
|
||||
"x":0.11,
|
||||
"y":0.8
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"label": "name2",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": false,
|
||||
"x":0.3,
|
||||
"y":0.3
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"label": "name3",
|
||||
"ip": "http://127.0.0.2",
|
||||
"status": true,
|
||||
"x":0.5,
|
||||
"y":0.6
|
||||
}
|
||||
]
|
||||
|
|
@ -32,7 +32,7 @@ class DetectorAPI:
|
|||
self.detection_classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
|
||||
self.num_detections = self.detection_graph.get_tensor_by_name('num_detections:0')
|
||||
|
||||
def processFrame(self, image):
|
||||
def process_frame(self, image):
|
||||
# Expand dimensions since the trained_model expects images to have shape: [1, None, None, 3]
|
||||
image_np_expanded = np.expand_dims(image, axis=0)
|
||||
# Actual detection.
|
||||
|
|
@ -45,10 +45,10 @@ class DetectorAPI:
|
|||
boxes_list = [None for i in range(boxes.shape[1])]
|
||||
for i in range(boxes.shape[1]):
|
||||
boxes_list[i] = (
|
||||
int(boxes[0,i,0] * im_height),
|
||||
int(boxes[0,i,1] * im_width),
|
||||
int(boxes[0,i,2] * im_height),
|
||||
int(boxes[0,i,3] * im_width)
|
||||
int(boxes[0, i, 0] * im_height),
|
||||
int(boxes[0, i, 1] * im_width),
|
||||
int(boxes[0, i, 2] * im_height),
|
||||
int(boxes[0, i, 3] * im_width)
|
||||
)
|
||||
|
||||
return boxes_list, scores[0].tolist(), [int(x) for x in classes[0].tolist()], int(num[0])
|
||||
|
|
@ -62,7 +62,7 @@ class Detector:
|
|||
def __init__(self, stream):
|
||||
self.model_path = "./server/model.pb"
|
||||
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
||||
self.threshold = 0.8
|
||||
self.threshold = 0.3
|
||||
self.stream = stream
|
||||
|
||||
|
||||
|
|
@ -71,9 +71,9 @@ class Detector:
|
|||
r, img = cap.read()
|
||||
if img is None:
|
||||
return img
|
||||
img = cv2.resize(img, (480, 270))
|
||||
|
||||
boxes, scores, classes, num = self.odapi.processFrame(img)
|
||||
img = cv2.resize(img, (720, 480))
|
||||
|
||||
boxes, scores, classes, num = self.odapi.process_frame(img)
|
||||
|
||||
# Visualization of the results of a detection.
|
||||
|
||||
|
|
@ -82,17 +82,14 @@ class Detector:
|
|||
if classes[i] == 1:
|
||||
if scores[i] > self.threshold:
|
||||
box = boxes[i]
|
||||
cv2.rectangle(img,(box[1],box[0]),(box[3],box[2]),(255,0,0),2)
|
||||
print("yes")
|
||||
|
||||
return img
|
||||
cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255, 0, 0), 2)
|
||||
return img, True
|
||||
else:
|
||||
print("no")
|
||||
|
||||
return img
|
||||
return img, False
|
||||
# cv2.imshow("preeview", img) # cv2.destroyWindow("preview")
|
||||
|
||||
def __del__(self):
|
||||
self.cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
requests.get("http://192.168.178.53/stop")
|
||||
#def __del__(self):
|
||||
|
||||
#self.cap.release()
|
||||
#cv2.destroyAllWindows()
|
||||
#requests.get("http://192.168.178.53/stop")
|
||||
|
|
|
|||
Loading…
Reference in New Issue