For years, I have been struggling with my network camera and its inability to correctly detect motion without generating a storm of false positive images. No matter how I configure the sensitivity of my camera, it is generating thousands of false-positive motion pictures each single day.
It seems as if the motion detection intelligence within these cheap cameras is quite limited and I doubt that it correctly works at all.
One aspect that annoyed me most is the fact that the motion detection algorithm is extremely sensitive to white noise like rain, wind or snow. Also foggy weather generates thousands of false detections.
To overcome that limited smartness of my camera, I spent a day implementing my own motion detection routine in Python.
It fetches the still image from the camera, blurs it a bit to reduce the effects of white noise, and converts it into grayscale.
Every camera image is compared with the previous camera image and a diff image is calculated.
The diff image is used to detect the changed boundaries, where I used the popular open-cv framework to find the changed boundaries and to calculate their area sizes.
In case a single changed area is larger than a given threshold, we consider this a valid motion and I store the motion picture on the local disk.
See below an example of the grayscale image that is fetched from the local camera:
Each motion results in a diff image as it is shown below:
Within the final motion image, the changed area is clearly highlighted and can be evaluated against the motion area threshold, as it is shown below:
The motion threshold is a simple way of ruling out small changing areas, such as white noise generated when trees and bushes move within windy weather.
Find my final motion detector on GitHub.
Shipping the motion detector in a Docker container
As I am running all my servers and routines on my Synology NAS Docker runtime, I was keen to also ship my camera motion detector as a Docker container.
The container can easily be configured by setting the two main environment variables, which are the URL for fetching your own image and the mapped folder name you want the container to store all the detected motion captures into.
See below a valid configuration of my motion detection docker container:
See below the local NAS folder, which is then mapped as folder ‘/motion’ into the Docker container, as it is shown in the image below:
In case you want to run the motion detection Docker container with your own camera images, you can fetch it from DockerHub.
Summary
By implementing and running my own camera motion detector as a Docker container I was able to dramatically reduce the number of false-positive motion detections.
As the motion detection Python script is pretty simple, I have all the flexibility to control and adapt the sensitivity of the detection algorithm.