diff --git a/rpi_camera_surveillance_system.py b/rpi_camera_surveillance_system.py new file mode 100644 index 0000000000000000000000000000000000000000..879cf8b962f938ce0a3204993c9da5a2229b3a42 --- /dev/null +++ b/rpi_camera_surveillance_system.py @@ -0,0 +1,99 @@ +# Source code from the official PiCamera package +# http://picamera.readthedocs.io/en/latest/recipes2.html#web-streaming + +import io +import picamera +import logging +import socketserver +from threading import Condition +from http import server + +PAGE = """\ +<html> +<head> +<title>Raspberry Pi - Live Footage</title> +</head> +<body> +<center><h1>Raspberry Pi - Live Feed</h1></center> +<center><img src="stream.mjpg" width="640" height="480"></center> +</body> +</html> +""" + + +class StreamingOutput(object): + def __init__(self): + self.frame = None + self.buffer = io.BytesIO() + self.condition = Condition() + + def write(self, buf): + if buf.startswith(b"\xff\xd8"): + # New frame, copy the existing buffer's content and notify all + # clients it's available + self.buffer.truncate() + with self.condition: + self.frame = self.buffer.getvalue() + self.condition.notify_all() + self.buffer.seek(0) + return self.buffer.write(buf) + + +class StreamingHandler(server.BaseHTTPRequestHandler): + def do_GET(self): + if self.path == "/": + self.send_response(301) + self.send_header("Location", "/index.html") + self.end_headers() + elif self.path == "/index.html": + content = PAGE.encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "text/html") + self.send_header("Content-Length", len(content)) + self.end_headers() + self.wfile.write(content) + elif self.path == "/stream.mjpg": + self.send_response(200) + self.send_header("Age", 0) + self.send_header("Cache-Control", "no-cache, private") + self.send_header("Pragma", "no-cache") + self.send_header( + "Content-Type", "multipart/x-mixed-replace; boundary=FRAME" + ) + self.end_headers() + try: + while True: + with output.condition: + output.condition.wait() + frame = output.frame + self.wfile.write(b"--FRAME\r\n") + self.send_header("Content-Type", "image/jpeg") + self.send_header("Content-Length", len(frame)) + self.end_headers() + self.wfile.write(frame) + self.wfile.write(b"\r\n") + except Exception as e: + logging.warning( + "Removed streaming client %s: %s", self.client_address, str(e) + ) + else: + self.send_error(404) + self.end_headers() + + +class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer): + allow_reuse_address = True + daemon_threads = True + + +with picamera.PiCamera(resolution="640x480", framerate=24) as camera: + output = StreamingOutput() + # Uncomment the next line to change your Pi's Camera rotation (in degrees) + # camera.rotation = 90 + camera.start_recording(output, format="mjpeg") + try: + address = ("", 8000) + server = StreamingServer(address, StreamingHandler) + server.serve_forever() + finally: + camera.stop_recording() diff --git a/whos_at_the_door.py b/whos_at_the_door.py index 299ebc987de8495ea74e30ca73f80d0861188573..15baef6373b61defcab7ece3987fdb2b05894bf0 100644 --- a/whos_at_the_door.py +++ b/whos_at_the_door.py @@ -1,24 +1,10 @@ -# Import smtplib for the actual sending function -import smtplib -import subprocess import time - -# Here are the email package modules we'll need -from email.mime.application import MIMEApplication -from email.mime.image import MIMEImage -from email.mime.multipart import MIMEMultipart from subprocess import call -from facial_recognition.facial_req import facial_rec - import grovepi -import cv2 -import os - from dht2 import temp +from facial_recognition.facial_req import facial_rec from zipper import zipper -import re - print("Welcome to Group 16's Advanced Doorbell Plus!") print("Please wait while we setup your doorbell") print("This will only take a moment.") @@ -45,22 +31,43 @@ SMTP_RECIPIENT = input( SMTP_SERVER = "smtp.office365.com" # Address of the SMTP server SSL_PORT = 587 -checker = True -while checker == True: + +# Ask the user if they want to run the rpi_camera_surveillance.py file which runs the camera + +while True: + run_live_feed = input("Would you like to view the live feed of the camera? (y/n): ") + if run_live_feed == "y": + call("python3 rpi_camera_surveillance.py", shell=True) + break + elif run_live_feed == "n": + break + else: + print("Please enter a valid option") + run_live_feed = input( + "Would you like to view the live feed of the camera? (y/n): " + ) + continue + + +while True: print() print("The process of adding photos of someone can only be done during startup") - print() - face_req = input("Would you like to add photos of someone? No: 0, Yes: 1): ") - - if face_req == "1" or face_req == "0": - checker = False + print("") + face_req = input("Would you like to add photos of someone? No: 0, Yes: 1: ") + + if face_req == "0": + print("Continuing without adding photos") + print("..................................") + break + elif face_req == "1": + call("cd facial_recognition; python3 headshots.py", shell=True) + print("We are just backing up your files on the cloud!") + call("cd facial_recognition; python3 cloudupload.py", shell=True) + print("..................................") + break else: - checker = True - print("Invalid Input. Must be 0, 1") -if face_req == "1": - call("cd facial_recognition; python3 headshots.py", shell=True) - print("We are just backing up your files on the cloud!") - call("cd facial_recognition; python3 cloudupload.py", shell=True) + print("Invalid input. Must be 0 or 1") + continue # Code keeps on looping in case of IO Error @@ -73,13 +80,13 @@ while True: # If something is detected for 250 loops, around 3 seconds, continue. # This reduces the chance of random motion triggering the security features. - while sustained == False: + while not sustained: ur_distance = grovepi.ultrasonicRead(ranger) if ur_distance < 100: sustained_track += 1 - + if sustained_track > 75: sustained = True @@ -101,20 +108,12 @@ while True: grovepi.analogWrite(buzzer, 0) print("Buzzer Stopped") - # Take a picture from the Raspberry Pi camera - # call(["raspistill -o screenshot.jpg -w 640 -h 480 -t 3000"], shell=True) - # print("Image Shot") - # Takes video from Pi camera call(["raspivid -o myvid.h264 -w 640 -h 480 -t 6000"], shell=True) zipper() grovepi.digitalWrite(led_status, 0) # Turn off the LED - # Uncomment the following if email is not being sent - # Running Facial Recognition based on users input - # command = "cd facial_recognition; python3 facial_req.py" - # call(command, shell=True) facial_rec(SMTP_RECIPIENT) except IOError: