/SmartDogHouse-SurveillanceSystem

Software for surveillance. Uses OpenCV for capturing video, running Object-Detection, sending MQTT messages for anomalies, streaming video.

Primary LanguagePythonMIT LicenseMIT

SmartDogHouse-SurveillanceSystem

Software for surveillance. Uses OpenCV for capturing video, running Object-Detection, sending MQTT message for anomalies, streaming video as a server.

CodeFactor Codacy Badge Quality Gate Status

smart doghouse logo

*actual results of an example image passed through the neural network

Install OpenCV

sudo apt-get install python3-opencv

test with

import cv2

Install ffmpeg

sudo apt install ffmpeg

if you are using VirtualBox add usb device : devices -> usb -> settings -> add -> select your camera.

test it with ffmplay

ffmplay /dev/video0

at this point, you should be able to test if everything is correct with camera_tester.py it should detect a device and display a window with the view.

you should be also able to execute the motion_detection_base.py

(for object detection) Download models

to use the neural network (NN) for object detection for the security system, you should download the models of the net. You can find some scripts in the model folder

bash ./download_yolo_v3_model.sh

then you can use the file object_detection_base.py with the params to pass the model of the NN you prefer.

(for MQTT notifications) Install MQTT client

both motion detection and object recognition systems can send an MQTT message if an anomaly is detected. The IoT sdk of Amazon AWS has been used:

pip install awsiotsdk

Remember to download cert, key. Put it in the flash folder and set up the secret.py file with the path to them. In this file you can also write the aws mqtt host, the mqtt port, client_id and topic.

You can test it with the class mqtt_tester.py

Then you can use the file object_detection_mqtt.py or motion_detection_mqtt.py to get a notification when an anomaly is detected.

(for streaming as a web server) Install Flask

If you want to stream as well the video you can download Flask, a micro web framework written in Python.

pip install flask

You can test it with stream_base.py and connect with a browser to localhost:5000

Now you should also be able to execute motion_detection_mqtt_stream.py

streaming over the internet

If you want to test stream outside you local network, you can use a service like "ngork" or any equivalent alternative. It has been tested with Ngrok so for completeness:

  • connect to the website, register, download Ngrok for your OS.
unzip /path/to/ngrok.zip
./ngrok authtoken <your auth otoken>
  • execute the stream file with python
ngrok tcp 5000 -region eu #(Specify between one of (us, au, ap, eu).)
  • collect the address, you can connect to it and watch the stream from anywhere!

Passing video frames from one device to another in the net.

if you need to pass the video frames from one device to another (to group cameras) (or for advanced elaboration to images): you can use the samples: sender_udp-py and receiver_udp.py

License

This project is under a License - see the LICENSE file for details