Michaela Merz's personal blog site

Security Cameras with Linux, Motion & DeepStack

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:

Detect motion

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.

Finally:

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.

2 thoughts on “Security Cameras with Linux, Motion & DeepStack

  1. Hi Michaela,

    I learned of you through your posting today, Monday, 5/9/2022, on the motion list. You and I share a lot of common interests. Right now I’m working on a project to create reliable security cameras using Raspberry Pi components. I’m currently in the morass of the Google Coral Dev Board which I bought in 2019 and never opened until about 3 or 4 weeks ago when I thought I’d be ready to dive into AI. Now I’m in the realm of getting gstreamer’s high watermark to run on the Coral Dev Board… not an easy task, and I’m still getting thwarted. I’m a big Gentoo fan since 2004. I published piano music under the now-defunct Editions Poole. I’m also a pianist — classical music. I also was an attorney for 40 years having resigned from practice recently. I’m currently employed at Oracle as a software developer, been there since 1999. I read your About page and just wanted to reach out to you and say thank you for posting what you did today on the motion forum and for publishing a blog piece. I was completely unaware of DeepStack.

    I passed your twitter onto my wife who does Twitter: https://twitter.com/mizblueprint

    Kind regards,
    John

  2. I found your posting on the motion list. I am working on a similar project to try and identify when pigeons land in a tree in our garden. I would be very interested in your script if you are willing to share it?
    many thanks, John

Leave a Reply to John A Cancel reply

Your email address will not be published. Required fields are marked *