Motion detection is often met in video analytics projects. It can be solved by comparing the variable part of the image with the unchanging, which allows distinguishing between the background and the moving objects. A simple motion detector can be easily found on the Internet, for example, at Pyimagesearch.com. This is a basic detector that does not handle:
- environmental changes;
- video stream noise that occurs due to various factors.
In this article, we will observe the implementation of an advanced Python-based motion detector that fits for the processing of noisy streams with high FPS expectations. The implementation relies on the OpenCV library for working with images and videos, the NumPy library for matrix operations, and Numba, which is used to speed up the part of operations that are performed in Python.
Noise is a natural or technical phenomenon observed in a video stream that should be ignored, otherwise it causes false positive detections. Noise examples:
- glare of sunlight;
- reflection of objects from transparent glass surfaces;
- vibrations of small objects in the frame – foliage, grass, dust;
- camera tremor due to random vibrations;
- flickering lighting fluorescent lamps;
- image defects due to low aperture, camera matrix quality;
- scattering of the picture due to network traffic delays or interference when using analog cameras.
There are many variants of noise, the result is the same – small changes in the image that occurs even in the absence of actual motion in the frame. Basic algorithms do not process these effects. The algorithm presented in this article copes with the noise. An example of noise can be seen in the following video fragment with a frame rate of 60 FPS: