added mock interface
This commit is contained in:
parent
478c225c6e
commit
c110f1f668
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File (Integrated Terminal)",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
{
|
||||
"name": "Python: Remote Attach",
|
||||
"type": "python",
|
||||
"request": "attach",
|
||||
"port": 5678,
|
||||
"host": "localhost",
|
||||
"pathMappings": [
|
||||
{
|
||||
"localRoot": "${workspaceFolder}",
|
||||
"remoteRoot": "."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Python: Module",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"module": "enter-your-module-name-here",
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
{
|
||||
"name": "Python: Django",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
"console": "integratedTerminal",
|
||||
"args": [
|
||||
"runserver",
|
||||
"--noreload",
|
||||
"--nothreading"
|
||||
],
|
||||
"django": true
|
||||
},
|
||||
{
|
||||
"name": "Python: Flask",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"module": "flask",
|
||||
"env": {
|
||||
"FLASK_APP": "app.py"
|
||||
},
|
||||
"args": [
|
||||
"run",
|
||||
"--no-debugger",
|
||||
"--no-reload"
|
||||
],
|
||||
"jinja": true
|
||||
},
|
||||
{
|
||||
"name": "Python: Current File (External Terminal)",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "externalTerminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
|
@ -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"]
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
import os
|
||||
import random
|
||||
import json
|
||||
from importlib import import_module
|
||||
import cv2
|
||||
from flask import Flask, jsonify, Response
|
||||
|
||||
application = Flask(__name__)
|
||||
clients = []
|
||||
cams = []
|
||||
with open("./clients.json", 'r', encoding='utf-8') as f:
|
||||
array = f.read()
|
||||
clients = json.loads(array)
|
||||
|
||||
with open("./cams.json", 'r', encoding='utf-8') as f:
|
||||
array = f.read()
|
||||
cams = json.loads(array)
|
||||
|
||||
|
||||
class VideoCamera(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()
|
||||
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
|
||||
# so we must encode it into JPEG in order to correctly display the
|
||||
# video stream.
|
||||
ret, jpeg = cv2.imencode('.jpg', image)
|
||||
return jpeg.tobytes()
|
||||
|
||||
@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)
|
||||
|
||||
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')
|
||||
|
||||
@application.route('/cam/<num>/stream')
|
||||
def cam_stream(num):
|
||||
|
||||
return Response(gen(VideoCamera(cams[int(num)]["ip"])),
|
||||
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(clients[0])
|
||||
application.run(host='127.0.0.1', port=80)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
[
|
||||
{
|
||||
"id": 0,
|
||||
"label": "cam1",
|
||||
"ip": "http://208.72.70.171:80/mjpg/video.mjpg",
|
||||
"status": true
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"label": "cam2",
|
||||
"ip": "http://89.29.108.38:80/mjpg/video.mjpg",
|
||||
"status": false
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"label": "cam3",
|
||||
"ip": "http://62.99.80.154:81/mjpg/video.mjpg",
|
||||
"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
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
requests
|
||||
flask
|
||||
gunicorn
|
||||
opencv-python
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
|
||||
\.vscode/
|
||||
|
||||
\.vscode/
|
||||
|
|
@ -62,15 +62,17 @@ class Detector:
|
|||
def __init__(self, stream):
|
||||
self.model_path = "./model.pb"
|
||||
self.odapi = DetectorAPI(path_to_ckpt=self.model_path)
|
||||
self.threshold = 0.3
|
||||
self.threshold = 0.8
|
||||
self.stream = stream
|
||||
|
||||
|
||||
def detect(self):
|
||||
cap = cv2.VideoCapture(self.stream)
|
||||
r, img = cap.read()
|
||||
img = cv2.resize(img, (500, 500))
|
||||
|
||||
if img is None:
|
||||
return img
|
||||
img = cv2.resize(img, (480, 270))
|
||||
|
||||
boxes, scores, classes, num = self.odapi.processFrame(img)
|
||||
|
||||
# Visualization of the results of a detection.
|
||||
|
|
@ -82,13 +84,15 @@ class Detector:
|
|||
box = boxes[i]
|
||||
cv2.rectangle(img,(box[1],box[0]),(box[3],box[2]),(255,0,0),2)
|
||||
print("yes")
|
||||
return True, img
|
||||
|
||||
return img
|
||||
else:
|
||||
print("no")
|
||||
|
||||
return False, img
|
||||
cv2.imshow("preview", img) # cv2.destroyWindow("preview")
|
||||
return img
|
||||
# cv2.imshow("preeview", img) # cv2.destroyWindow("preview")
|
||||
|
||||
def __del__(self):
|
||||
self.cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
requests.get("http://192.168.178.53/stop")
|
||||
|
|
@ -4,28 +4,34 @@ import detector as dt
|
|||
import cv2
|
||||
|
||||
if __name__ == "__main__":
|
||||
t = 30 # seconds a person can leave the room for
|
||||
t = 1 # seconds a person can leave the room for
|
||||
t0 = time.time()
|
||||
time.clock()
|
||||
elapsed = 0
|
||||
#stream = "https://192.168.178.56:8080/video"
|
||||
stream = "http://217.128.254.187:8083/mjpg/video.mjpg"
|
||||
|
||||
detector = dt.Detector(stream)
|
||||
music_playing = False
|
||||
|
||||
|
||||
#cv2.startWindowThread()
|
||||
#cv2.namedWindow("preview")
|
||||
|
||||
while True:
|
||||
elapsed = time.time() - t0
|
||||
if elapsed > t and music_playing:
|
||||
r = requests.get("http://192.168.178.53/stop")
|
||||
if r.status_code == 200:
|
||||
music_playing = False
|
||||
|
||||
result, img = detector.detect()
|
||||
if result and not music_playing:
|
||||
tmp = time.time()
|
||||
img = detector.detect()
|
||||
print(time.time()-tmp)
|
||||
if img is not None and not music_playing:
|
||||
r = requests.get("http://192.168.178.53/play")
|
||||
if r.status_code == 200:
|
||||
music_playing = True
|
||||
t0 = time.time()
|
||||
cv2.imshow("preview", img) # cv2.destroyWindow("preview")
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
cv2.imshow("preview", img)
|
||||
cv2.waitKey(1)
|
||||
|
||||
Loading…
Reference in New Issue