Motion detection is the process of detecting a change in the position of an object relative to its surroundings or a change in the surroundings relative to an object. Motion detection can be achieved by either mechanical or electronic methods. It can be applied to numerous business or everyday problems. In industrial fields, motion detectors are used on assembly lines to keep track of the number of products and to shut down dangerous equipment if a person gets too close. Here are a few other ways motion sensors are used to:

• save energy by using motion sensor lighting in unoccupied spaces
• open and close automatic doors
• turn on and off automatic water faucets and toilets
• turn on lights when a person enters a room
• control ATM displays
• issue tickets at parking lots

In this article, we will consider motion detection by analyzing the scene from CCTV cameras for security purposes. A simple algorithm for motion detection by a fixed camera compares the current image with a reference image and simply counts the number of different pixels. Since images will naturally differ due to such factors as varying lighting, camera flicker, and CCD dark currents, pre-processing is useful to reduce the number of false positive alarms. However, you do not need to constantly track the whole movement on the scene. For example, you parked your car near your house on the street and you want to detect all unusual movements only near your car. You do not need your alarm system to become activated for each pedestrian or any car driving on the street. That’s why it is best to track only some regions through the camera.

As mentioned before the simple difference between the reference image and current image gives bad results. Later on, we will show the rough description of motion detection algorithm. But first, we need to eliminate camera sensor dark noises. It can be achieved by estimating and applying math pre-processing to some of the frames (depends on hardware characteristics and alert system tolerance) and setting a resulting image as a reference image. Also before differentiating between the two, it is a good idea to blur the reference and current images by applying the Gaussian or median blur. Below you can see the results of differentiation between the reference and current images.

Now we have this pixel difference in particular regions of interest on the scene. The simplest way to detect motion is by the calculation of standard deviation of all pixels in the region. Thus, we can estimate constant noise level and calculate the needed system alert level for each region.

Here we include sample videos that demonstrate how your security camera can become a motion detector.

Insert math as
$${}$$