changed to port 5000 (not server)

processed pic is shown
This commit is contained in:
Patrice 2019-06-07 18:48:36 +02:00
parent a1aa2847e1
commit 98a456847b
8 changed files with 117 additions and 97 deletions

View File

@ -50,7 +50,7 @@ namespace FrontEnd
static Communicator() 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.Clear();
client.DefaultRequestHeaders.Accept.Add( client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json")); new MediaTypeWithQualityHeaderValue("application/json"));

View File

@ -2,7 +2,7 @@
{ {
"id": 0, "id": 0,
"label": "cam1", "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, "client_id": 0,
"status": true, "status": true,
"x":0.2, "x":0.2,

View File

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

View File

@ -1,10 +1,12 @@
import io
import json import json
import time import time
import requests import requests
import detector as dt import detector as dt
import cv2 import cv2
import _thread import _thread
from flask import Flask, jsonify, Response import copy
from flask import Flask, jsonify, Response, make_response, send_file
######### ########### ######### ###########
### Init ### ### Init ###
@ -14,13 +16,12 @@ application = Flask(__name__)
clients = [] clients = []
cams = [] cams = []
lastImages = list(range(0,4))
with open("./server/clients.json", 'r', encoding='utf-8') as f: with open("./server/clients.json", 'r', encoding='utf-8') as f:
array = f.read() clients = json.loads(f.read())
clients = json.loads(array)
with open("./server/cams.json", 'r', encoding='utf-8') as f: with open("./server/cams.json", 'r', encoding='utf-8') as f:
array = f.read() cams = json.loads(f.read())
cams = json.loads(array)
class VideoCamera(object): class VideoCamera(object):
"""Video stream object""" """Video stream object"""
@ -55,26 +56,34 @@ def main():
elapsed = 0 elapsed = 0
stream = cam["ip"] stream = cam["ip"]
detector = dt.Detector(stream) detector = dt.Detector(stream)
music_playing = client_ip = clients[cam["client_id"]]["status"] clientStatus = clients[cam["client_id"]]["status"]
client_ip = "http://" + clients[cam["client_id"]]["ip"] clientIp = clients[cam["client_id"]]["ip"]
elapsed = time.time() - t0 elapsed = time.time() - t0
if elapsed > t and music_playing: if elapsed > t and clientStatus:
r = requests.get(client_ip + "/stop") try:
if r.status_code == 200: #r = requests.get(clientIp + "/stop")
#if r.status_code == 200:
clients[cam["client_id"]]["status"] = False clients[cam["client_id"]]["status"] = False
cam["status"] = False
except:
print("request error")
tmp = time.time() tmp = time.time()
img = detector.detect() img, result = detector.detect()
print(time.time()-tmp) print(cam["client_id"], result, time.time()-tmp)
if img is not None and not music_playing: lastImages[cam["id"]] = img
r = requests.get(client_ip + "/play")
if r.status_code == 200: if result and not clientStatus:
try:
#r = requests.get(clientIp + "/play")
#if r.status_code == 200:
clients[cam["client_id"]]["status"] = True clients[cam["client_id"]]["status"] = True
cam["status"] = True
t0 = time.time() t0 = time.time()
# TODO noch nicht sicher wie ich das verarbeirtete Bild ausgebe except:
#cv2.imshow("preview", img) print("request error")
#cv2.waitKey(1)
######### ########### ######### ###########
### Routes ### ### Routes ###
@ -82,28 +91,28 @@ def main():
@application.route('/client/') @application.route('/client/')
def client_list(): def client_list():
json = clients return jsonify(clients)
return jsonify(json)
@application.route('/client/<num>/info') @application.route('/client/<num>/info')
def client_info(num): def client_info(num):
json = clients[int(num)] return jsonify(clients[int(num)])
return jsonify(json)
@application.route('/cam/') @application.route('/cam/')
def cam_list(): def cam_list():
json = cams return jsonify(cams)
return jsonify(json)
@application.route('/cam/<num>/info') @application.route('/cam/<num>/info')
def cam_info(num): def cam_info(num):
json = cams[int(num)] return jsonify(cams[int(num)])
return jsonify(json)
@application.route('/cam/<num>/stream') @application.route('/cam/<num>/stream')
def cam_stream(num): def cam_stream(num):
return Response(gen(VideoCamera(cams[int(num)]["ip"])), return Response(gen(VideoCamera(cams[int(num)]["ip"])), mimetype='multipart/x-mixed-replace; boundary=frame')
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, () ) _thread.start_new_thread(main, () )
application.run(host='0.0.0.0', port=5000, threaded=True)
application.run(host='127.0.0.1', port=80, threaded=True)

View File

@ -2,22 +2,31 @@
{ {
"id": 0, "id": 0,
"label": "cam1", "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, "client_id": 0,
"status": true "status": true,
"x":0.2,
"y":0.8,
"angle": 130
}, },
{ {
"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, "client_id": 1,
"status": false "status": false,
"x":0.4,
"y":0.2,
"angle": 190
}, },
{ {
"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, "client_id": 2,
"status": true "status": true,
"x":0.9,
"y":0.1,
"angle": 270
} }
] ]

View File

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

View File

@ -32,7 +32,7 @@ class DetectorAPI:
self.detection_classes = self.detection_graph.get_tensor_by_name('detection_classes:0') 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') 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] # Expand dimensions since the trained_model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image, axis=0) image_np_expanded = np.expand_dims(image, axis=0)
# Actual detection. # Actual detection.
@ -45,10 +45,10 @@ class DetectorAPI:
boxes_list = [None for i in range(boxes.shape[1])] boxes_list = [None for i in range(boxes.shape[1])]
for i in range(boxes.shape[1]): for i in range(boxes.shape[1]):
boxes_list[i] = ( boxes_list[i] = (
int(boxes[0,i,0] * im_height), int(boxes[0, i, 0] * im_height),
int(boxes[0,i,1] * im_width), int(boxes[0, i, 1] * im_width),
int(boxes[0,i,2] * im_height), int(boxes[0, i, 2] * im_height),
int(boxes[0,i,3] * im_width) int(boxes[0, i, 3] * im_width)
) )
return boxes_list, scores[0].tolist(), [int(x) for x in classes[0].tolist()], int(num[0]) 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): def __init__(self, stream):
self.model_path = "./server/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.3
self.stream = stream self.stream = stream
@ -71,9 +71,9 @@ class Detector:
r, img = cap.read() r, img = cap.read()
if img is None: if img is None:
return img return img
img = cv2.resize(img, (480, 270)) img = cv2.resize(img, (720, 480))
boxes, scores, classes, num = self.odapi.processFrame(img) boxes, scores, classes, num = self.odapi.process_frame(img)
# Visualization of the results of a detection. # Visualization of the results of a detection.
@ -82,17 +82,14 @@ class Detector:
if classes[i] == 1: if classes[i] == 1:
if scores[i] > self.threshold: if scores[i] > self.threshold:
box = boxes[i] box = boxes[i]
cv2.rectangle(img,(box[1],box[0]),(box[3],box[2]),(255,0,0),2) cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255, 0, 0), 2)
print("yes") return img, True
return img
else: else:
print("no") return img, False
return img
# cv2.imshow("preeview", img) # cv2.destroyWindow("preview") # cv2.imshow("preeview", img) # cv2.destroyWindow("preview")
def __del__(self): #def __del__(self):
self.cap.release()
cv2.destroyAllWindows() #self.cap.release()
requests.get("http://192.168.178.53/stop") #cv2.destroyAllWindows()
#requests.get("http://192.168.178.53/stop")