Skip to content

Commit

Permalink
#9 Added support for two cameras
Browse files Browse the repository at this point in the history
Two cameras can now be used simuntaniosly. The plan is to make an implementation that can use n cameras in the future. The problem is the dynamic allocation of the ports and the dynamic allocation of the gui elements for the video streaming. But more on that perhaps in the future.
  • Loading branch information
kcuric committed Jan 4, 2020
1 parent f702618 commit ed82a8d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
13 changes: 10 additions & 3 deletions client/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from modules.Streamer import Streamer
from modules.Recorder import Recorder
import sys, signal
import sys
import signal
import argparse

recorder = Recorder(0)
stream = Streamer('127.0.0.1', 5005) #35.204.145.0
parser = argparse.ArgumentParser()
parser.add_argument('port', metavar='P', type=int, help='Desired port.')
parser.add_argument('--cam', metavar='C', type=int, nargs='?', const=0, help='Desired cam.')
args = parser.parse_args()

recorder = Recorder(args.cam)
stream = Streamer('127.0.0.1', args.port) #35.204.145.0

# SIGNAL HANDLING
def receive_signal(signal_number, frame):
Expand Down
41 changes: 24 additions & 17 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,49 @@

# SOCKET CONFIG
ip = "0.0.0.0"
port = 5005
server_adress = (ip, port)
ports = [5005, 5006]
sockets = list()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(server_adress)
for port in ports:
new_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
new_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
new_socket.bind((ip, port))
sockets.append(new_socket)

# DETECTOR CONFIG
detector = Detector()

def rec():
while True:
data, addr = sock.recvfrom(65535)
if(detector.find_faces(data)):
print("INTRUDER!")
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + data + b'\r\n')

# SIGNAL HANDLING
def receive_signal(signal_number, frame):
global detector, sock, app
del detector
print("\nDetector released.")
sock.close()
for socket in sockets:
del socket
print("Socket closed.")
del app
print("Application exited.")
sys.exit()

def rec(sock):
while True:
data, addr = sock.recvfrom(65535)
if(detector.find_faces(data)):
print("INTRUDER!")
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + data + b'\r\n')

@app.route('/')
def index():
return render_template('index.html')

@app.route('/video_feed')
def video_feed():
return Response(rec(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/camera1')
def camera1():
return Response(rec(sockets[0]), mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/camera2')
def camera2():
return Response(rec(sockets[1]), mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
signal.signal(signal.SIGINT, receive_signal)
Expand Down
4 changes: 2 additions & 2 deletions server/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<div class="container">
<h1>DIY Survailence System</h1>
<p>Running the app.py</p>
<img src="{{ url_for('video_feed') }}">
<img src="{{ url_for('video_feed') }}">
<img src="{{ url_for('camera1') }}">
<img src="{{ url_for('camera2') }}">
</div>
</body>
</html>

0 comments on commit ed82a8d

Please sign in to comment.