Qengineering / RPiMotionCam

Raspberry Pi motion surveillance camera with live feed, email notification and event triggered cloud storage
https://qengineering.eu/shop.html
BSD 3-Clause "New" or "Revised" License
29 stars 2 forks source link
cpp email email-notification gdrive google-drive livefeed livestream motion-camera motion-detection raspberry-pi raspberry-pi-3b raspberry-pi-4 raspberry-pi-zero raspberry-pi-zero-2-w sd-card-image surveillance surveillance-camera text-message usb usb-stick

RPiMotionCam

https://user-images.githubusercontent.com/44409029/156776492-51b29ff9-b3c7-4e85-9587-974a2d363a77.mp4

Raspberry Pi motion surveillance camera with live feed, email notification and event triggered gdrive storage

License

This application is a fully-featured security Raspberry Pi camera. It can be built with the Raspberry Pi 4, 3 or the tiny Zero 2.
With an inexpensive RPi V1 camera ($ 7,=), you'll have your security camera up and running in no time.
You will automatically receive an email when the camera detects a movement.
At the same time, a optional video recording will be saved to SD-card, USB stick or your Google drive.
You can view your footage in your browser at any time.
You don't need to be able to program.
However, the used C++ source code comes with the image.


Installation.


Preparations.

There are a few settings needed before the application will work properly.


Donations.

Writing the app was a lot of work. Still, we want to give you all the source code for free. As well as the FFmpeg streaming solutions.
However, we really appreciate it if you show your appreciation by making a donation.
paypal


output image


How does it work?

The application detects movements in a scene and can trigger a motion event. This motion event can send an email and/or start a recording.

A common background image is generated from an average of many previous video frames. The latest frame is subtracted from this background. Only pixels values not equal to the corresponding background pixel value are marked. All marked pixels are counted, and a percentage is calculated. This percentage can trigger the motion event if it's greater than the set_trigger setting.
You will need to experiment with set_trigger and reset_trigger to see what suits you best in your situation. Detecting a person in front of your door requires other settings than detecting the neighbours' car in the backyard.

At the same time, this frame is averaged with the other recently captured images. It means that once a movement is stopped, it gradually vanish into the background. Like the car in the video above. When it was parked, it slowly disappears. The time it takes to vanish is defined by the constant TAU_BACKGROUND at line 36 in General.h. If you want to change it, you need to re-compile the MainEvent app. It is not a setting like the ones in Settings.txt.

Note that sudden changes in light can also trigger an event. Think of clouds sliding in front of the sun or swaying branches of a tree. There is not much you can do about it. In some cases, it helps by excluding certain regions in the frames from the background subtractor. For instance, a busy street with much traffic at the upper part of your footage. You have to program it yourself in the MainEvent app with OpenCV.


Motivation.

The main goal was to write the simplest possible app without compromising functionality. We think we have succeeded in that. Many functions are controlled with just a few small C++ programs. An experienced programmer can understand our programs within half a day instead of spending days struggling to encapsulate the functionality in a complex framework like MotionOS.

Of course, this strategy comes with a price.


C++ code.

The C++ code is available and allows you to modify the application to your needs. All resources are in the software folder. As well as the Code::Blocks project files to build the apps. For information on how to run a project, see our guide to OpenCV and Code::Blocks.

:point_right: Before you start programming, make sure you have removed the overlay functionality, if enabled.

The autostart links to executable files in /usr/local/bin. You need to move your executables from your project file /bin/Release/ to /usr/local/bin once programming is complete. Otherwise, autostart will not use your last exe.
More information about programs found at /usr/local/bin on this Wiki page.


Good to know.

You have a latency of about 10 seconds. This time is inherent to the HLS streaming. It takes some time to collect all the information from the stream, get the individual packets and 'glue' them together into one video stream.
By the way, thanks to this latency, you will receive your emails 5 seconds before the actual movement is visible in your browser so you can log in.

Many free sites convert an email to a text message. At the same time, you can port forward your Raspberry Pi, making it accessible with your private IP and user-defined port number. It is even possible to get a nice domain name for your camera (https://wwww.MyBackYardRPi.com). Google something like "free DNS for your IP camera".


Tip.

We used the cheap RPi camera V1 for € 6,70. It works fine. However, the tiny plug from the embedded sensor to the PCB often can be loose. Somehow the software still supported the camera but didn't receive any video anymore. It took quite a while before we discovered the cause; the connector. Once glued, it now functions perfectly.

output image

You can use the command $ vcgencmd get_camera to see if your camera is working.

output image