Security Cameras with Linux, Motion & DeepStack
I like to know what’s going on around my house. I had a number of security cameras installed on my old house but I just recorded the data streams and was able to view the footage whenever there was a reason. I wanted more from the cameras at my new house. Like email notifications and text messages whenever a person was in the view of my cameras.
But that wasn’t easy. My original plan was to install ZoneMinder on our in-house server to do the heavy lifting. While ZoneMinder might do the job, it was just too troublesome to get it set up on a server that already has a number of things to do. Same with shinobi. I am sure it’s great software, but installation into a working platform was too much trouble.
I finally found “motion” which is a very compact environment that is able to handle all my cameras and it allowed me to configure the motion detection to the point where false alarms where almost completely eradicated. But in order to exclude all potential noise sources, I had to really “dumb” down the cameras with masks and filter settings. And it still triggered alerts, especially at night when our neighbor across the street pulled his car from the garage. At that point I realized that motion detection alone wouldn’t be sufficient to create a more or less bullet proof notification system.
I needed “AI” to detect persons.
There are a number of ways to integrate machine learning into a camera security environment. Most of those environments rely on “openCV” and a number of python scripts to get the job done. Again – I found the installation and working environment too complex and more like a puzzle with different parts that need to be glued together.
I finally found the right combination to get what I wanted. The “motion” software platform would allow me to declare area of interests and to reliably detect motion, I just needed to check if the motion event is of interest to me. And in order to do that, I installed “DeepStack” into a docker container – which took about 3 minutes.
Here is the logical chain of events as it is running on my server right now:
As mentioned before, I use the “motion” software because it is compact and has great configuration options to get exactly what you want. The “on_event_start” variable can be configured to trigger a shell script or run some other software.
Running A Script
Because I had PHP on my server anyway, I created a small PHP script that pulls up to five images from a camera, HTTP-posts it to “Deep Stack” and parses the result. When a person is detected with a confidence greater than 50%, I use the X/Y coordinates provided by “DeepStack” to draw a box around the object and store the image on disk.
When the PHP script exists with a value > 0 (the confidence in percent) I use “mpack” and “msmtp” to email the image to me. I can also use “msmtp” to send an email to my cell phone network to deliver a text push message.
A very reliable and easy to create solution. Works like a charm. I was able to relax the motion criteria a bit more so that even less prominent events get the chance to be verified by “Deep Stack”. No more false alarms.
Since “motion” handles its tasks very efficiently, my server isn’t overly bothered as the “DeepStack” process is only called whenever we have had motion.
Needless to say, I also record all streams 24/7 with ffmpeg.
Michaela Merz is an entrepreneur and first generation hacker. Her career started even before the Internet was available. She invented and developed a number of technologies now considered to be standard in modern web-environments. Among other things, she developed, founded, managed and sold Germany’s third largest Internet Online Service “germany.net” . She owns a music production business but still very much enjoys “hacking” modern technologies like block chain, IoT and mobile-, voice- and web-based services.