GuardMyPi
Protecting your berries from unauthorised tampering!
GuardMyPi

Table of Contents

Introduction

GuardMyPi is a home security system centred around the Raspberry Pi 3. It utilises the Pi NoIR Camera to monitor a room or entrance point in a house. Facial recognition software is used to distinguish between house members (including pets) and intruders. If an intruder is detected, a notification is sent to the user via a web application.

Authors

Magnus Bell Cochran - 22587.nosp@m.76B@.nosp@m.stude.nosp@m.nt.g.nosp@m.la.ac.nosp@m..uk

Pedro Hernandez Gelado - 22620.nosp@m.04h@.nosp@m.stude.nosp@m.nt.g.nosp@m.la.ac.nosp@m..uk

Aidan Porteous - 22456.nosp@m.28p@.nosp@m.stude.nosp@m.nt.g.nosp@m.la.ac.nosp@m..uk

Project Link: https://github.com/phgelado/guardmypi

Required Hardware

This project can be completed within a £50 budget (excluding the Raspberry Pi) with the following components:

Building OpenCV from Source

  1. Downloading pre-built OpenCV4
    wget https://github.com/sol-prog/raspberry-pi-opencv/releases/download/opencv4rpi2.1/opencv-4.1.0-armhf.tar.bz2
  2. Extract the archive
    tar xvf opencv-4.1.0-armhf.tar.bz2
  3. Move the extracted archive to the /opt folder
    sudo mv opencv-4.1.0 /opt
  4. Remove the archive (optional)
    rm opencv-4.1.0-armhf.tar.bz2
  5. Install video and image support packages
    sudo apt install libjpeg-dev libtiff-dev libjasper-dev libpng-dev libwebp-dev libopenexr-dev
    sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libdc1394-22-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
  6. Install packages needed for OpenCV's interface
    sudo apt install libgtk-3-dev libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
  7. Install packages for OpenCV to run at a good speed
    sudo apt install libatlas-base-dev liblapacke-dev gfortran
  8. Add OpenCV to the system path
    cd ~
    echo 'export LD_LIBRARY_PATH=/opt/opencv-4.1.0/lib:$LD_LIBRARY_PATH' >> .bashrc
    . .bashrc
  9. Restart the terminal or log back in to the RPi if connected via SSH
  10. Install git if necessary
    sudo apt-get install git
  11. Clone a config file to use OpenCV for C++
    git clone https://gist.github.com/sol-prog/ed383474872958081985de733eaf352d opencv_cpp_compile_settings
    cd opencv_cpp_compile_settings/
    sudo cp opencv.pc /usr/lib/arm-linux-gnueabihf/pkgconfig
    cd ~
    rm -rf opencv_cpp_compile_settings/
  12. Check OpenCV has installed correctly on the RPi
    pkg-config --modversion opencv

Streamer

  1. Ensure you have CMake installed, as well as the dependencies mjpg-streamer uses:
    sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
  2. Clone the mjpg-streamer repository you can find here https://github.com/jacksonliam/mjpg-streamer.
    git clone https://github.com/jacksonliam/mjpg-streamer
  3. Access the mjpg-streamer directory.
    cd mjpg-streamer
    cd mjpg-streamer-experimental
  4. Build and install mjpg-streamer using CMake.
    make
    sudo make install

Dataplicity

Dataplicity is a simple to use, safe and free tool for you to access and control your RaspberryPi remotely, allowing you to setup and start your alarm from anywhere, as well as accessing the camera's live video feed.

Similar to a VPN, but easier to install, it also allows you to access your Pi's local port 80 (http://localhost:80) through a domain, which is where the Pi's live camera feed is streamed to. Installing Dataplicity is very simple! Follow the instructions here: https://www.dataplicity.com/.

MotionDetector

The system has to be capable of detecting changes in individual frames. The changes in these frames are what allow computer visual applications to detect motion. However, while consecutive frames are not identical the MotionDetector class applies a Gaussian blur to the data to filter high frequency noise that would irregularly trigger the motion warning and the rest of the system.

Take a frame from a video feed of an empty room:

background.png

If a person (or pet) walks into the feed, the detector will find large changes in contours by taking the absolute difference of the two frame's pixel intensities leaving only the regions containing motion:

frame_diff.png

The detector acts as an event-base trigger invokes methods such as facial recognition and human detection.

motiondetected.png

Unlock

In order to let the user unlock the system various methods were added to the Unlock class; Facial Recognition Unlock::face() and QR Detection Unlock::QRUnlock().

Facial Recognition

Facial recognition is achieved using the LPBH algorithm. By using a pre-trained algorithm with faces including the desired residents. Predicting each face outputs a confidence level and ID number according to the images fed into the trained database. Including a condition with a threshold for a confidence level (currently set to 123) will allow a user to tighten or loosen the strictnes of their recognition process.

facerecognition.png

After recognising the user within a specified time frame of 10s then the system is disarmed and waits for a QR code to lock and re-arm the system

See also
Unlock::QRLock()
facerecognised.png

QR Code Detection

Another method that is implemented to lock and unlock the system are QR codes that can be easily generated and shown on a mobile phone. When a user would like to leave the house showing a QR Code representing "lock" will then freeze the program for 60s to allow the user to leave before the system is then re-armed.

qrlock.png

ObjectDetector

The object detector is a class with methods of recognising different objects such as pets with potential to incldude methods that recognise other objects such as gestures. Currently the pet detection ObjectDector::detect attempts to recognise a grayhound, but training algorithms can be re run with a bigger database of pets.

Detect

Before running the human detection method, the system looks for domestic pets (if applicable) as to not send a false alarm notification to the resident(s) if their pet was captured in the frame. If a pet is detected then no flags are raised and the system continues as normal. Otherwise the human detection method is called.

petdetection.png

Intruder Alert

If a resident of the house is not recognised either using facial recognition nor QR Code detection, then the intruder flag is set high. This invokes both the web streaming service and email notification method, both used to capture feed of any intruder and also alert the user to notify the relevant authorities.