Skip to content

The ultimate security tool to protect your berries from unauthorised tampering.

License

Notifications You must be signed in to change notification settings

phgelado/guardmypi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GuardMyPi

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

GuardMyPi

The ultimate security tool to protect your berries from unauthorised tampering. guardmypi.com »

Facebook Instagram LinkedIn Twitter Hackaday



Table of Contents
  1. About The Project
  2. Getting Started
  3. How to use
  4. Usage Examples
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

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. If the camera detects motion, object detection methods are used to check whether the source of motion is a human or a pet. If a human, facial recognition software is used to determine if it is a household member, or if not recognised, an intruder. If an intruder is detected, the user will receive an email notifying them, and will be able to access the camera via remote streaming from our website. Additionally, the Pi will save video evidence of the intruder which can be accessed later.

You can find our doxygen documentation/Wiki for this project here.

Built With

Hardware used

Real-time responsiveness

Testing carried out using the high_resolution_clock C++ class with 5 sample runs (excluding and repeating testing if an outlier i.e. more than +/- 3σ was identified), on a Raspberry Pi 3, with a 4× ARM Cortex-A53, 1.2GHz CPU.

  • Motion Detection Class: 34 (+/- 4) ms
  • QR Code Class: 251 (+/- 2) ms
  • Facial Recognition Class: 199 (+/- 5) ms

For the mjpg-streamer and email sending latencies are dependant on broadband, client-server location and method of connection between the RasberryPi and the local router.

Getting Started

Prerequisites

To be able to run this project locally you will need to install the following dependencies:

Installation of CMake

sudo apt-get install cmake

Installation of OpenCV4 on Raspberry Pi

  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
  1. Extract the archive
    tar xvf opencv-4.1.0-armhf.tar.bz2
  2. Move the extracted archive to the /opt folder
    sudo mv opencv-4.1.0 /opt
  3. Remove the archive (optional)
    rm opencv-4.1.0-armhf.tar.bz2
  4. 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
  1. Install packages needed for OpenCV's interface
sudo apt install libgtk-3-dev libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
  1. Install packages for OpenCV to run at a good speed
sudo apt install libatlas-base-dev liblapacke-dev gfortran
  1. Add OpenCV to the system path
cd ~
echo 'export LD_LIBRARY_PATH=/opt/opencv-4.1.0/lib:$LD_LIBRARY_PATH' >> .bashrc
. .bashrc
  1. Restart the terminal or log back in to the RPi if connected via SSH

  2. Install git if necessary

sudo apt-get install git
  1. 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/
  1. Check OpenCV has installed correctly on the RPi
pkg-config --modversion opencv

Installation of mjpg-streamer on Raspberry Pi

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

Installation of 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.

Installation of mailutils

sudo apt install mailutils

Installation of git-lfs

This is necessary due to the large size of the facial recognition .yml file.

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install

How to use

Building the Program

git clone https://github.com/phgelado/guardmypi
cd guardmypi
cmake .
make
./newmain

To set up the streaming, in a separate terminal run the following command from your root, i.e. pi@raspberrypi:

sudo LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f ./guardmypi/ -n test.jpg" - o "output_http.so -w /home/pi/mjpg-streamer/mjpg-streamer-experimental/www -p 80"

Dataplicity should already be up and running from installation, double check you can see and access your device here.

Customisation

Note that the program is currently set up to run for a specific user. If you wish to customise the program for your own needs, here are some useful links:

  • Facial recognition using OpenCV. A user can use pictures of their own face to train a facial recognition model. This can then be saved in a yml file and replace the 'guardingthepi.yml' file.
  • Training an object detection model using OpenCV OpenCV can also be trained to detect objects using Haar Cascades. This has been applied to the pet detection in our case, and a user could train a cascade to recognise their own pet's face. Please note that both the training for this and facial recognition should be carried out on a more powerful device than a Pi, for example a laptop or PC. This requires installation of OpenCV3 rather than 4 on the device - just follow this link and make sure to use the 3.4 branch when building.
  • You can create your own unlock and lock keys, that you will be able to convert into a QR Code readable by GuardMyPi. We encourage you to regularly change your unlock key if possible, and to use high encryption (256+ bit) keys. You can create encryption keys at this link and then copy and paste your key into a QR Code Generator, ensuring you click on "text". You can then download or take a screenshot of this QR Code, maybe print it out if you're old school! Keep it in a safe place, it will allow you to unlock and lock GuardMyPi. Note: from installation the QR code keys are "unlock" and "lock".
  • Make sure to change the email address given in the "guardmypi.cpp" file to your own.

Usage Examples

Image of Motion Detection Image of Aidan Image of QR Code Image of Kasper

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Magnus Bell Cochran - 2258776B@student.gla.ac.uk

Pedro Hernandez Gelado - 2262004h@student.gla.ac.uk

Aidan Porteous - 2245628p@student.gla.ac.uk

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

Acknowledgements