This commit is contained in:
parent
28ff955a41
commit
0cff9a509b
|
|
@ -12,11 +12,11 @@ playing = False
|
||||||
def index():
|
def index():
|
||||||
global playing, p, w
|
global playing, p, w
|
||||||
if playing:
|
if playing:
|
||||||
return 406
|
return str(406)
|
||||||
else:
|
else:
|
||||||
playing = True
|
playing = True
|
||||||
p = w.play()
|
p = w.play()
|
||||||
return 200
|
return str(200)
|
||||||
|
|
||||||
@app.route('/stop')
|
@app.route('/stop')
|
||||||
def test():
|
def test():
|
||||||
|
|
@ -24,9 +24,9 @@ def test():
|
||||||
if playing:
|
if playing:
|
||||||
playing = False
|
playing = False
|
||||||
p.stop()
|
p.stop()
|
||||||
return 200
|
return str(200)
|
||||||
else:
|
else:
|
||||||
return 406
|
return str(406)
|
||||||
|
|
||||||
|
|
||||||
port = int(os.environ.get('PORT', 81))
|
port = int(os.environ.get('PORT', 81))
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -15,7 +15,7 @@ application = Flask(__name__)
|
||||||
|
|
||||||
clients = []
|
clients = []
|
||||||
cams = []
|
cams = []
|
||||||
lastImages = list(range(0,4))
|
lastImages = list(range(0,10))
|
||||||
with open("./clients.json", 'r', encoding='utf-8') as f:
|
with open("./clients.json", 'r', encoding='utf-8') as f:
|
||||||
clients = json.loads(f.read())
|
clients = json.loads(f.read())
|
||||||
|
|
||||||
|
|
@ -55,45 +55,49 @@ def gen_processed(num):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
detector = dt.Detector()
|
detector = dt.Detector()
|
||||||
t = 1 # seconds a person can leave the room for
|
t = 5 # seconds a person can leave the room for
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
elapsed = 0
|
elapsed = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for cam in cams:
|
cam = cams[2]
|
||||||
|
|
||||||
stream = cam["ip"]
|
|
||||||
|
|
||||||
clientStatus = clients[cam["client_id"]]["status"]
|
|
||||||
clientIp = clients[cam["client_id"]]["ip"]
|
|
||||||
|
|
||||||
elapsed = time.time() - t0
|
|
||||||
if elapsed > t and clientStatus:
|
stream = cam["ip"]
|
||||||
try:
|
|
||||||
r = requests.get(clientIp + "/stop")
|
clientStatus = clients[cam["client_id"]]["status"]
|
||||||
if r.status_code == 200:
|
clientIp = clients[cam["client_id"]]["ip"]
|
||||||
clients[cam["client_id"]]["status"] = False
|
|
||||||
cam["status"] = False
|
|
||||||
except:
|
|
||||||
print("request error")
|
|
||||||
|
|
||||||
tmp = time.time()
|
elapsed = time.time() - t0
|
||||||
try:
|
if elapsed > t and clientStatus:
|
||||||
img, result = detector.detect(stream)
|
try:
|
||||||
|
r = requests.get(clientIp + "/stop")
|
||||||
|
#if r.status_code == 200:
|
||||||
|
clients[cam["client_id"]]["status"] = False
|
||||||
except:
|
except:
|
||||||
continue
|
print("request error")
|
||||||
print(cam["client_id"], result, time.time()-tmp)
|
|
||||||
lastImages[cam["id"]] = img
|
|
||||||
|
|
||||||
if result and not clientStatus:
|
tmp = time.time()
|
||||||
|
try:
|
||||||
|
img, result = detector.detect(stream)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(cam["id"], result, time.time()-tmp)
|
||||||
|
lastImages[cam["id"]] = img
|
||||||
|
|
||||||
|
if result:
|
||||||
|
cam["status"] = True
|
||||||
|
if 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
|
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
except:
|
except:
|
||||||
print("request error")
|
print("request error")
|
||||||
|
else:
|
||||||
|
cam["status"] = False
|
||||||
|
|
||||||
|
|
||||||
######### ###########
|
######### ###########
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,30 @@
|
||||||
"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": 2,
|
||||||
"status": false,
|
"status": false,
|
||||||
"x":0.4,
|
"x":0.4,
|
||||||
"y":0.2,
|
"y":0.2,
|
||||||
"angle": 190
|
"angle": 190
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 3,
|
||||||
"label": "cam3",
|
"label": "cam4",
|
||||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
"ip": "http://82.150.206.177/cgi-bin/faststream.jpg?stream=half&fps=15&rand=COUNTER",
|
||||||
|
"client_id": 1,
|
||||||
|
"status": false,
|
||||||
|
"x":0.75,
|
||||||
|
"y":0.4,
|
||||||
|
"angle": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"label": "cam5",
|
||||||
|
"ip": "http://79.189.131.176:99/videostream.cgi?user=admin&pwd=",
|
||||||
"client_id": 2,
|
"client_id": 2,
|
||||||
"status": false,
|
"status": false,
|
||||||
"x":0.9,
|
"x":0.8,
|
||||||
"y":0.1,
|
"y":0.8,
|
||||||
"angle": 270
|
"angle": 90
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -62,7 +62,7 @@ class Detector:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.model_path = "./model.pb"
|
self.model_path = "./model.pb"
|
||||||
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
||||||
self.threshold = 0.7
|
self.threshold = 0.6
|
||||||
|
|
||||||
def detect(self, stream):
|
def detect(self, stream):
|
||||||
cap = cv2.VideoCapture(stream)
|
cap = cv2.VideoCapture(stream)
|
||||||
|
|
@ -70,7 +70,13 @@ 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, (1000, 543))
|
|
||||||
|
scale_percent = 60 # percent of original size
|
||||||
|
width = int(img.shape[1] * scale_percent / 100)
|
||||||
|
height = int(img.shape[0] * scale_percent / 100)
|
||||||
|
dim = (width, height)
|
||||||
|
|
||||||
|
img = cv2.resize(img, dim)
|
||||||
|
|
||||||
boxes, scores, classes, num = self.odapi.process_frame(img)
|
boxes, scores, classes, num = self.odapi.process_frame(img)
|
||||||
res = False
|
res = False
|
||||||
|
|
@ -81,9 +87,12 @@ class Detector:
|
||||||
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)
|
||||||
res = True
|
res = True
|
||||||
|
return img, res
|
||||||
else:
|
else:
|
||||||
res = False
|
res = False
|
||||||
return img, res
|
return img, res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#def __del__(self):
|
#def __del__(self):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue