Motion detection system

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.


In today's competitive environment, the security concerns have grown tremendously. In the modern world, possession is known to be 9/10'ths of the law. Hence, it is imperative for one to be able to safeguard one's property from worldly harms such as thefts, destruction of property, people with malicious intent etc. Due to the advent of technology in the modern world, the methodologies used by thieves and robbers for stealing has been improving exponentially. Therefore, it is necessary for the surveillance techniques to also improve with the changing world. With the improvement in mass media and various forms of communication, it is now possible to monitor and control the environment to the advantage of the owners of the property. The latest technologies used in the fight against thefts and destruction are the video surveillance and monitoring. By using the technologies, it is possible to monitor and capture every inch and second of the area in interest. However, so far the technologies used are passive in nature, i.e., the monitoring systems only help in detecting the crime but do not actively participate in stopping or curbing the crime while it takes place. Therefore, we have developed a methodology to detect the motion in a video stream environment and this is an idea to ensure that the monitoring systems not only actively participate in stopping the crime, but do so while the crime is taking place. Hence, a system is used to detect any motion in a live streaming video and once motion has been detected in the live stream, the software will activate a warning system and capture the live streaming video.


In recent years, motion detection has attracted a great interest from computer vision researchers due to its promising applications in many areas, such as video surveillance, traffic monitoring or sign language recognition. However, it is still in its early developmental stage and needs to improve its robustness when applied in a complex environment. Several techniques for moving object detection have been proposed among them the three representative approaches are temporal differencing, background subtraction and optical flow. Temporal differencing based on frame difference, attempts to detect moving regions by making use of the difference of consecutive frames (two or three) in a video sequence. This method is highly adaptive to dynamic environments, but generally does a poor job of extracting the complete shapes of certain types of moving objects. Background subtraction is the most commonly used approach in presence of still cameras. The principle of this method is to use a model of the background and compare the current image with a reference. In this way the foreground objects present in the scene are detected.

The method of statistical model based on the background subtraction is flexible and fast, but the background scene and the camera are required to be stationary when this method is applied. Optical flow is an approximation of the local image motion and specifies how much each image pixel moves between adjacent images. It can achieve success of motion detection in the presence of camera motion or background changing. According to the smoothness constraint, the corresponding points in the two successive frames should not move more than a few pixels. For an uncertain environment, this means that the camera motion or background changing should be relatively small. The method based on optical flow is complex, but it can detect the motion accurately even without knowing the background.

Architecture of Project


Motion Detection System is to detect the motion in front of a camera. A Web camera with an USB interface is used to take images. Images acquired from the web camera are passed to Personal Computer (PC) via USB port. PC consists of inbuilt USB controllers which will control externally connected hardware devices. This USB port is interfaced to CPU through PIC bus. Images acquired by Web camera are processed by PC with the help of MATLAB workspace. MATLAB process those images with the help of Image Acquisition Toolbox.

After the complete processing of images in MATLAB the result will be displayed on it. Here Monitor is used as a display device in this project.

Working Principle

For obtain this objective a Web camera is used to capture the video. To process this frames MATLAB workspace is used. Frames taken by camera are loaded onto MATLAB workspace. Then those frames are displayed on axis Window of Graphical User Interface (GUI). Now these images passed through a Manual window to find area of interest. Image taken by camera will be in 3D format as it is in RGB form. It is difficult to process a RGB images, to reduce processing complexity of images this frames are converted to gray scale Images.

After conversion of images, they are heightened to improve the brightness and contrast (i.e. to reduce the noises produced by lighting). Before processing has started a boundary is created and this boundary can be enlarged. Now this gray scale image is converted into binary format in order to process further. Now using predefined functions in MATLAB workspace difference between two frames is calculated. And the resultant images obtained by the difference from those two frames are used to find the motion detection. When there is any motion the resultant image will have a white portion in the motion area and remaining area will be blank. If there is no motion then image will be totally blank.

Now the calculations are made to find the motion detected in the place using this calculations. The area were white portion is calculated by summing 1's in the overall image. Since the 1's will be obtained at white area in the image. Now all 1's are summed up to find whether the sum crosses the predefined threshold. If the total exceeds the predefined threshold then a Motion Detected massage displayed else a No motion Detection message will be displayed

Image Processing Techniques Used:

  • Image Conversion
  • Image Enhancement
  • Image Windowing
  • Image Arithmetic

With the Help of Image conversion technique RGB frames are converted into gray scale, for reducing the complexity of 3D image format. And later converted to Binary format. After conversion of images, they are heightened to improve the brightness and contrast (i.e. to reduce the noises produced by lighting) by using Enhancement technique. This technique is used to display the image on the windows. The perfect difference of two frames can be calculated with help of image arithmetic technique and then using which the motion of the object can be detected.

Introduction About Video Surveillance

In 1965, Reporters from different countries suggested to use video as surveillance cameras. Since the video is cheapest source which can be used in public areas. And video surveillance started by closed circuit television monitoring (CCTV). When videocassette was released into market, video surveillance became most popular. Using analog technologies the videos which are recorded were used as evidence. A analog video surveillance uses a camera, monitor and a VCR.

Old tube cameras used in analog video surveillance were only useful in day time, and VCR got a capacity of storing a footage of eight hours only. Those were the disadvantages with the analog video surveillance, for this owners/employees of a system are supposed to change the video tape on regular interval. As video tapes are re-used, they don't lost for long period of time. The other major issue was using it in night times (or) in cloudy days. Due to in sufficient lighting provided to old tube camera they faced some problems. Even thought it was a good idea, and this technology is not yet vanished till today.

Later a Charged Coupled Device camera (CCD), which had an inbuilt microchip computer technology. In 1990's video surveillance made a significant progress in technology by introducing digital multiplexing. As cost of the digital multiplexer is reduced, there was a radically change in surveillance industries by starting recording large no of cameras at once.

Advantages of digital video recorders are listed below:

  • The compression capability of video taping is changing drastically using different video formats, this allows to store more information on to hard drive
  • The cost of a hard drive, which has dropped dramatically in recent years.
  • The storage capacity of a hard drive, which has increased dramatically in recent years.

Importance of Digital video surveillance raised as cost of it dropped with the computer revolution. Using Digital video surveillance, regular changing of video tapes has vanished. Now footage of month's can be stored into hard disk without any problem. As the video recorded is in digital form it is far clearer then the grainy images (Image taken by analog technology cameras). There are different image processing technique for digitally stored images which enhance it in various ways (add light effects, change colors, reverse black and white) to find the important features of image.

Requirement of video surveillance

While it is important to understand the various places video surveillance can be used it is also important to asses the risks involved in the protection of a certain item. In the recent years, as more and more items such as art are gaining importance, the prices of such things are also going through the roof. Therefore, technology has come in the forefront for protection and surveillance of such goods and items.

The following are the statistics of thefts in places such as shops, residences and in public places in our country, India in a particular year. Of the 50 reported thefts in one year, the breakage of thefts can be shown as the following:

  • Display Cases 19
  • Open displays 10
  • Pictures 04
  • Other displays 02
  • At night 06
  • From stores 02
  • Long timescale 04
  • Other 03

Even though technology as improved from past few decades, it has still long way to go. From the above statistics we can clearly say that technology is gaining focus on security surveillance. By enhancing security surveillance technology many crimes can we stopped.

Motion Detection in Live VIDEO STREAM

When all is said and done, surveillance systems should be a reflection of the real world we live in. As people become more and more security savvy, they will demand real protection for their property. The new digital video systems will have to raise that security to a new level. They should make the customers feel good. Scare off a few troublemakers. And those who do try to beat the system should face a far greater risk of getting caught. Hence, the new digital video surveillance systems should be able to provide a high sense of security. The peace of mind can only be achieved when the person is assured that he will be informed of any thefts of his property while they are in progress. He would also feel more secure if he can be guaranteed that the surveillance system that he uses will not only give him evidence against the perpetrators but also try to stop the thefts from taking place in the first place. Therefore, to achieve such kind of security Motion Detection in the live video stream is implemented. The motion detection systems will not only be monitoring the areas of interest but will also keep an active lookout for any motion being produced.


Aim: In the project, I aimed to build such a surveillance system, which can not only detect motion, but will

  1. Warn the user of the intrusion and
  2. Record the footage of the video from the moment the motion was detected.

Coding Language:

To fulfill aim, I have used strong computing software called MATLAB. Advantage of MATLAB: Basically the advantage of using MATLAB is that MATLAB is an interpreted language for numerical computation. It allows one to perform numerical calculations, and visualize the results without the need for complicated and time consuming programming. MATLAB allows its users to accurately solve problems, produce graphics easily and produce code efficiently. Disadvantage of MATLAB: The only problem with MATLAB is that since MATLAB is an interpreted language, it can be slow, and poor programming practices can make it unacceptably slow. If the processing power of the computing machine is low the MATLAB software takes time to load and execute any code making the code execute very slowly.

Reason for Selection: MATLAB provides Image Acquisition and Image Processing Toolboxes which facilitate us in creating a good GUI and an excellent code.


The objective of this work was to develop a surveillance system which would detect motion in a live video feed and if motion is detected, then to activate a warning system and store the video feed for future reference and processing purposes. The activation of an alarm would help in nullifying a threat of security and storing of video provides a proof of such malicious activity. Keeping the work objective in mind, we firstly developed basic system architecture as shown in the Figure 2.2.

The system architecture, which we developed, describes how the system component interacts and work together to achieve the overall system goals. It describes the system operation, what each component of the system does and what information is exchange. The architecture was designed for basically getting an idea of how the actual system works and operates.

System Architecture Functioning

The system architecture is going to function in following way:

Capturing the live video feed through a web cam:

To detect motion we first have to capture live video frames of the area to be monitored and kept under surveillance this is done by using a web cam which continuously provides a sequence of video frames in a particular speed of FPS (frames per second).

Comparing the current frames captured with previous frames to detect motion:

For checking whether any motion is present in the live video feed, we compare the live video frames being provided by the web cam with each other so that we can detect changes in these frames and hence predict the occurrence of some motion.

Storing the frames on the memory if motion is detected:

If motion is being detected, we would require storing such motion so that the user can view it in the near future. This also helps the user in providing a legal proof of some inappropriate activity since a video coverage can be used as a proof in the court of law.

Indicating through an alarm when the motion is detected:

The user may want to be notified immediately that there has been some intrusion detected by the software, hence an alarm system is included in the software. This alarm system immediately activates a WAV file format audio alarm signal if any kind of motion is detected hence. This helps in preventing any kind of breach of security at that moment of time.


Our work is motion based change detection in .avi video format. Before beginning with the work, one of the important tasks was deciding the various tasks required to implement the work. Therefore, we performed a brain storming session and decided various important tasks which would be required in completion of the work such as:

  • Analysis and study of the problem definition,
  • Deciding the requirements of the system being developed,
  • System architecture containing the following sub function:
  • Capturing,
  • Comparing
  • Storing and
  • Indication of motion
  • Developing the code and
  • Documentation.

After deciding the various important tasks in our work, we decided that the platform on which we are going to develop our code will be MATLAB. We choose MATLAB because various video acquisition and analysis functions are pre-defined in MATLAB that would make the development of our work much easier. Finally, just before we started developing the code, we designed a rough GUI and created a design, which would suit our needs and perform all activities, which were desired by us and would be easier to use by anybody.



The detection of motion essentially requires the user to perform two major steps. They are: foremost step is to setup the hardware for acquiring the video data in which the motion is to be detected and the later step is to actually device an algorithm by which the motion will be detected. The AVI video format is actually an interleave of Audio and Video. The video stream is stored or acquired as a series of frames occurring in an ordered sequence one after the other.

Acquisition Setup:

The MATLAB programming language is used to store data in the form of matrices. Therefore MATLAB can provide quick interface with data matrices. The software provides for frame acquisition from hardware devices such as web cams or digital cameras as long as the devices are correctly initialized by the programmer. Therefore, in order to allow quick setup with the image acquisition devices, MATLAB Function directory provides a host of predefined functions by which the user can inquire about the various different devices currently connected and then setup the required device with MATLAB so that it can acquire and store data at run time.


The Image Acquisition Toolbox is a collection of functions that extend the capability of the MATLAB numeric computing environment. The toolbox supports a wide range of image acquisition operations, including

  1. Acquiring images through many types of image acquisition devices, from professional grade frame grabbers to USB-based Webcams.
  2. Viewing a preview of the live video stream.
  3. Triggering acquisitions (includes external hardware triggers).
  4. Configuring callback functions that execute when certain events occur.
  5. Bringing the image data into the MATLAB workspace.

Many of the toolbox functions are MATLAB M-files. You can view the MATLAB code for these functions using the statement

type function_name

You can extend the capabilities of the Image Acquisition Toolbox by writing your own M-files, or by using the toolbox in combination with other toolboxes, such as the Image Processing Toolbox and the Data Acquisition Toolbox. The Image Acquisition Toolbox also includes a Simulink block, called the Video Input block, that can be used to bring live video data into a model.

Basic Image Acquisition Procedure

The basic steps required to create an image acquisition application by implementing a simple motion detection application. The application detects movement in a scene by performing a pixel-to-pixel comparison in pairs of incoming image frames. If nothing moves in the scene, pixel values remain the same in each frame. When something moves in the image, the application displays the pixels that have changed values. To use the Image Acquisition Toolbox to acquire image data, you must perform the following basic steps:




GUIDE, the MATLAB Graphical User Interface Development Environment, provides a set of tools for creating graphical user interfaces (GUIs). These tools simplify the process of laying out and programming GUIs.

Laying Out a GUI:

The GUIDE Layout Editor enables you to populate a GUI by clicking and dragging GUI components -- such as buttons, text fields, sliders, axes, and so on -- into the layout area. It also enables you to create menus and context menus for the GUI. Other tools, which are accessible from the Layout Editor, enable you to size the GUI, modify component look and feel, align components, set tab order, view a hierarchical list of the component objects, and set GUI options. The following topic, Laying Out a Simple GUI, uses some of these tools to show you the basics of laying out a GUI. GUIDE Tools Summary describes the tools.

Running the Simulation from the GUI:

The GUI Simulate and store results button callback runs the model simulation and stores the results in the handles structure. Storing data in the handles structure simplifies the process of passing data to other sub function since this structure can be passed as an argument.

When a user clicks on the Simulate and store results button, the callback executes the following steps: Calls sim, which runs the simulation and returns the data that is used for plotting. Creates a structure to save the results of the simulation, the current values of the simulation parameters set by the GUI, and the run name and number. Stores the structure in the handles structure. Updates the list box String to list the most recent run.


The MATLAB interface allows the user to define the commands to be performed at the run time. Once the user setup of the video source is complete the algorithm comes into play. The algorithm is built to take advantage of the strength of MATLAB i.e. to store data as a form of matrices. The frames acquired are stored in the MATLAB directory as matrix in which each element of the matrix contains information about the pixel value of the image at a particular location. Therefore, the pixel values are stored in the workspace as a grid where every element of the matrix corresponds to an individual pixel value.

Since MATLAB considers each matrix as one large collection of values instead of a bunch of individual values it is significantly quicker in analyzing and processing the image data. The algorithm hence checks each frame being acquired by the device with the previously acquired frame and checks for the difference between the total values of each frame. A threshold level is set by the user with which the difference of values is compared. If the difference exceeds the threshold value the motion is said to be detected in the video stream.

Function Explanation:

Function Name:

The Function name Mstart is executed as the Monitor button in the GUI is pressed by the user. It takes the value of the GUI from the user and updates it in the workspace.


The set command is used to change the looks and controls available to the user in the GUI. It is used to change the value of the buttons and is also used to prevent the user from pressing buttons which cannot logically occur again. As the number of buttons that can be pressed by the user reduces, the amount of confusion in the users mind will also reduce as the process will be self guiding thereby reducing the number of errors or bugs and to ensure that user's experience is hassle free.

Video Input:

The video input command is used to setup the video source for the rest of the program to be run. The code presentation for above snippets of the processes is performed by MATLAB when the video input command is called into play. The initial four commands are given to inquire about the presence and status of the camera that has been stated in the program. The subsequent function is carried out if MATLAB is able to connect and initialize the specified device. If the connection is successfully established MATLAB just sets its input location to the device, which has been initialized, and then keeps on catching the frames as input data from the device.


The Uiputfile function is used to allow the user to define the name and storage space of the output file of the video. This function is essential for two major reasons:

  1. It allows the MATLAB to save the file exactly where the user specifies thereby ensuring the user can easily find the storage location.
  2. It allows the user to name the file thereby allowing him to keep a record of each and every file without the chances of any previous record being overwritten.


The AVI object command is used to create an object file of the type AVI. The AVI file is a standard video format with a predefined method of encryption. Therefore, a class file is already present in MATLAB and the AVI object file defines an instance to create the AVI file in which the motion is being stored. The object created is set to the filename specified by the user in the previous function.


The get function is used to interface with the GUI file. It checks the status and returns the current value of the GUI button as specified.

Start Vid:

The Start function is used to start the video acquisition device to get the frame from the device object.

Stop Vid:

The Stop function is very important in the video acquisition device. The Start function begins the video stream entering as input to MATLAB. The stop function will stop this input. If the function is not used, the video stream continues in the path already started by MATLAB. If the user will try to use it again, MATLAB will not be able to start it again as the path will be busy. It will therefore stop the reusability of the program unless the whole of MATLAB reinitializes.

Delete Vid:

The delete function is used to delete the temporary frames stored by MATLAB in the object file. This function will free up the workspace as well as enable the function to reuse the pathname.


The imaqreset function is very important as it resets the acquisition device altogether. It ensures that the frame buffer in the object is free and completely new at the time the device restarts. It also resets the device therefore ensuring that there is no device present for acquisition and the device can be used for other uses.


This section describes about the further development of the video and the audio units along with the help and the graphical user interfaces.


The software produces an AVI video file as it monitors the area in view. Irrespective of the fact that most modern operating systems would provide various different software's to play video files in AVI format, the user should be able to view the file without having to switch programs and searching for it. Hence, it is of the utmost importance that there should be a video player that plays the video stream that has been produced.


The uigetfile function is used to retrieve a file from the hard drive. The function is used here to ensure that the user has the option : choose the movie file that the user wants to playback. Although it may seem illogical since only one file is created in each instance, the user may want to keep a track of other files in the record or may want to play a previously recorded video.


The mplay function is a built in video player in the MATLAB library function. It can play a host of multimedia files as well as be called from the MATLAB command prompt. It has a Graphical User Interface to play the video file thereby allowing the user to stop, play as well as forward and rewind the file. The mplay function is predefined and encrypted in MATLAB to be run with the various programs created by the user. The source code for the player is protected.


In order for the software to act as a surveillance system it is important to provide a mechanism to raise an alarm in case motion is detected in the video stream. However, conversely, stealth may be required in a few cases where alarms may prove more harmful. Therefore, an alarm function is required which will allow the user to choose the audio function as per his requisites.


The get function is used to interface with the GUI file. It checks the status and returns the current value of the GUI button as specified.


The global function is used to specify that the global variable is being called into play. MATLAB ensures that every variable is local only to its local function to reduce complexity and to reduce conflicts between similarly named variables. The global function makes the variable accessible to all functions in the program to allow different functions to change variables according to the necessity [11].

Wave read:

The wav read function is a MATLAB function to read and store audio files in the wave audio format. It can search and find the first RIFF chunk of data in the file. It then opens the file for the wave player and searches for the next subsequent chunks of data. It does not open the subsequent chunks but just reads the type of chunk that is present and forwards it to the player.

Audio player:

The audio player function is an audio playing file, which can play a host of audio signals in MATLAB. It essentially initializes the audio file sent to it by the waveread or auread function and creates an audio signal object which returns the number of bits each signal takes up.


The play function starts and runs the audio signal object created in the audio player function. It plays each audio sample as provided in the audio file as it enters in the audio player. The following are snippets of the play function of the audio player. It checks for any present errors and if not, plays the audio sample.


The help function is a prerequisite for any good software to ensure that the user can use each and every function of the program. The help file of any software should be detailed with examples or instructions about using the software to improve user's interaction with the software.


The mdhelp is a completely new gui file which acts as a popup when called as a function. It contains a static text box that acts as a frame in which there are instructions stored about how to use the given software. The text frame contains a step-by-step guide to running and interfacing with the software to help the user make various decisions about the options he wants exercise.


The modern operating systems allow for almost every program to run using visual icons and Interfaces. Hence, most users would be put off from using software's that are completely text based to run. MATLAB provides the programmer with MATLAB GUIDE which is a tool for generating user interfaces for the programs.


An integration of Optical Flow Method, Temporal Differencing Method and Double Background Filtering (DBF) Method with Morphological Processing is represented. The main goal of this algorithm is to separate the background interference and foreground information effectively and detect the moving object accurately. Firstly, temporal differencing method is used to detect the coarse motion object area for the optical flow calculation. Secondly, the DBF method is used to get and maintain a stable background image to address changes in environmental conditions and is also used to reduce the background interference, and locate the moving object position. Morphological processing is also used and combined with DBF to gain the better results. Different from the paper, a new improved strategy is proposed which not only improves the capability of detecting the object in motion, but also reduces the computation demands.

Real-time detection is important in video surveillance to find the moving objects. The algorithm used in this project integrates the Temporal Differencing Method, Double Background Filtering (DBF) method, Morphological Processing Method and Optical Flow Methods to get accurate results.

Temporal differencing method is used to detect initial common motion areas through which calculation can be achieved easily and accurately. This method also helps in getting real-time accuracy.

The DBF method keeps a stable background frame to find the environmental changes. And also helps to eliminate the background interferences by separating the moving objects from it.

The morphological processing methods are adopted and combined with the DBF to get improved results. The most attractive advantage of this algorithm is that the algorithm does not need to learn the background model from hundreds of images and can handle quick image variations without prior knowledge about the object size and shape. The algorithm has high capability of anti-interference and preserves high accurate rate detection at the same time. It also demands less computation time than other methods for the real-time surveillance. The effectiveness of the proposed algorithm for motion detection is demonstrated in a simulation environment and the evaluation results are reported here.


The method is depicted in the flow chart of Figure 4.1. As can be seen, the whole algorithm is comprised of four steps:

  1. Temporal differencing method, which is used to detect the initial coarse object motion area;
  2. Optical flow detection, which is based on the result of (1) to calculate optical flow for each frame;
  3. Double background filtering method with morphological processing, which is used to eliminate the background interference and keep the foreground moving information;
  4. Motion area detection, which is used to detect the moving object and give the alarming in time.

The final processing result is a binary image in which the background area and moving object area are shown as white color, the other areas are shown in black color and the top right corner is the alarm symbol.


Temporal differencing is based on frame difference which attempts to detect moving regions by making use of the difference of consecutive frames (two or three) in a video sequence. This method is highly adaptive to static environment. So temporal differencing is good at providing initial coarse motion areas. The two subsequent 256 level gray images at time t and t+1, I (x, y, t) and I (x, y, t +1) , are selected and the difference between images is calculated by setting the adaptive threshold to get the region of changes. The adaptive threshold Td can be derived from image statistics. In order to detect cases of slow motion or temporally stopped objects, a weighted coefficient with a fixed weight for the new observation is used to compute the temporal difference image Id (x, y, t) d as shown in following equations:

Where w is a real number between 0 and 1 which describes the temporal range for difference images. Ia (x, y, t -1) is initialized to an empty image. In our method, we set d T as the three times of mean value of Ia (x, y, t +1) and w = 0.5 for all the results. Fig.2 below shows the results of temporal differencing method under a simulation environment which has a static background of our laboratory. From the results, we can see that the temporal difference is a simple method for detecting moving objects in a static environment and the adaptive threshold d T can restrain the noise very well. But if the background is not static, the temporal difference method will very sensitive to any movement and is difficult to differentiate the true and false movement. So the temporal difference method can only be used to detect the possible object moving area which is for the optical flow calculation to detect real object movement.


Optical flow is a concept which is close to the motion of objects within a visual representation. The term optical flow denotes a vector field defined across the image plane. Optical flow calculation is a two-frame differential method for motion estimation. Such methods try to calculate the motion between two image frames which are taken at interval t at every pixel position. Estimating the optical flow is useful in pattern recognition, computer vision, and other image processing applications. In this chapter, a optical flow method entitled Lucas-Kanade Method is introduced.

Lucas-Kanade Method

To extract a 2D motion field, Lucas-Kanade method is often employed to compute optical flow because of its accuracy and efficiency. Barron compared the accuracy of different optical flow techniques on both real and synthetic image sequences, it is found that the most reliable one was the first-order, local differential method of Lucas and Kanade. Liu studied the accuracy and the efficiency trade-offs in different optical flow algorithms. The study has been focused on the motion algorithm implementation in real world tasks. Their results showed that Lucas Kanade method is pretty fast. Galvin evaluated eight optical flow algorithms. The Lucas-Kanade method consistently produces accurate depth maps, and has a low computational cost, and good noise tolerance. The Lucas-Kanade method is trying to calculate the motion between two image frames which are taken at time t and t + dt for every pixel position. As a pixel at location (x,y,t) with intensity Ia (x,y,t) will have moved by dx, dy and dt between the two frames, the following image constraint equation can be given:

Simplified Calculation:

The theoretical calculation procedure of the optical flow method is explained in the above subsection, but for the requirement of practical application, some operation characteristics between matrices can be used to simplify the complexity of calculation. For the calculation of invertible matrix in (16), the companion matrix method can be used:

Gradient Operator:

From the operation expression of optical flow, the estimation of the gradient for x-direction, y-direction and t-direction, has a great influence on the final results of optical flow calculation. The most common gradient operators used in optical flow calculation are Horn, Robert, Sobel, Prewitt, Barron and so on. In this paper, a better 3D Sobel operator is used which was proposed in [26]. This operator uses three different templates to do the convolution calculation for three frames in a row along the directions of x, y and t and to calculate the gradient along three directions for central pixels of the template in the middle frame. Fig.3 shows the operators.

Results of Optical Flow Detection:

The optical flow information for every frame of an image is calculated. As shown in Fig.4, the optical flow of frames It, It+1, , , ,It+n in a period time [t, t+n] are represented as n F1 ,F2 , ,Fn (here i represent i sampling period in t+i expression). The result of optical flow is shown as a binary image and the adaptive threshold is selected to distinguish the moving pixel from the still pixel. The pixels whose optical flow values are greater than threshold will be considered as moving pixels and are shown in white.

Where Fn (i, j) n is the optical flow value, Fn D(i, j) n is the result of optical flow detection and the adaptive threshold T is select as median value of Fn (i, j) n whose value is above 0. Figure 4.5 shows the results of optical flow which is calculated based on the result of temporal difference. The simulation environment this time is not a static background which the column bar curtain is moving caused by the winds. From the results, we can see that the optical flow with adaptive threshold based on temporal difference reserves the information of moving object very well. However, because of the background interference of the image, the real object movement still can not be separated from the background. So the method of double background filtering with morphological processing is introduced in the next section to deal with this problem.


By using the optical flow method, two types of optical flow information are obtained, which are the interference information of image background and the information of image pixel with any possibility of real object movement. In the real situation, because of the environment such as light, vibration and so on, the interference information of the background still can be detected. Sometimes, it is difficult for the real object movement to be differentiated from the background interference. In this section, the method of DBF with morphological processing is used to get rid of the background interference and separate the moving object from it. Firstly, the DBF method and its corresponding results are discussed. Then the morphological processing methods are introduced and the improved results are also demonstrated.

Double Background Filtering:

In this paper, a novel approach is developed to update the background. This approach is based on a double background principle, long-term background and short-term background. For the long-term background, the background interference information which has happened in a long time is saved. For the short-term background, the most recent changes are saved. These two background images are modified to adequately update the background image and to detect and correct abnormal conditions. During practical tests, we found that although the optical flow of background interference can be detected without moving object, it is relatively stable for some specific areas on the image and the amount of this optical flow doesn't change very much. For the area where the moving object appears, the amount of optical flow must change significantly in the specific area. According to these characteristics, the moving object should be easily detected if the information of the background and foreground can be separated. In this paper, a method entitled Double Background Filtering (DBF) is proposed, which consists of four steps. Figure.4.6 shown below explains the method in a tabular way.

  1. The optical flow information of the first five frames is accumulated for saving the optical flow information of the background interference. Let 5 A be the accumulation matrix, which is defined with the same size as the video images and set the initial value as zeros. To compute this matrix the formula below is applied:
  2. The optical flow information of the last three frames is accumulated for moving object detection. Let 3 A be the accumulation matrix and computed as follow:
  3. By comparing the results of steps (1) and (2) and eliminating the overlap optical flow, the rest should be the optical flow which represents as the real movement. The algorithm to detect whether a pixel B(i, j) belongs to an object with salient motion is described as follows
  4. Background Updating, This step is an updating function of the new value of the accumulation matrix, both 5 A and 3 A are set to zero, with the new video frame input, the four steps above are then repeated.

In this method, there are always two unused frames during the process, the purpose of this is to separate the background and moving object effectively. When the moving object appears in the last three frames, the information of moving object will not be lost while the background is updating. Figure 4.7 shows the result of double background filtering method. From the results, we can see that for the background without moving object, the background interference can not be eliminated completely and for the background with moving object, although the moving object area can be detected, the background interference is still exit. So how to get rid of the background interference and preserve the information of moving object at the same time is most important problem we are facing. The morphological processing method is introduced in next section to solve this problem.

Morphological Image Processing:

Morphological image processing is a collection of techniques for digital image processing based on mathematical morphology which is a nonlinear approach that is developed based on set theory and geometry [29]. Morphological image processing techniques are widely used in the area of image processing, machine vision and pattern recognition due to its robustness in preserving the main shape while suppressing noise. When acting upon complex shapes, morphological operations are able to decompose them into meaningful parts and separate them from the background, as well as preserve the main shape characteristics. Furthermore, the mathematical calculation involved in mathematical morphology includes only addition, subtraction and maximum and minimum operations without any multiplication and division. There are two fundamental morphological operations which are dilation and erosion and many of the morphological algorithms are based on these two primitive operations. Dilation of the set A by set B which is usually called as structure element, denoted by AÅ B, is obtained by first reflecting B about its origin and then translating the result by x. All x such that A and reflected B translated by x that have at least one point in common form the dilated set.

In our experiments, we use three morphological operators, dilation, opening and closing. The first one, dilation, is applied in the image with the accumulation optical flow for the first five frames, which is after the first step of DBF method. The dilation operator expands the area of background interference to make it eliminated efficiently in the third step of DBF method. The other two operators, opening and closing, are applied in the image with the accumulation optical flow for last three frames, which is after second step of DBF method. The opening operator is used first to eliminate the noise which consists of isolated points and closing operator is used immediately after filling up the holes and gaps. The structure element in both operations is SE = {1,1,1;1,1,1;1,1,1}. Figure 4.8 shows the results of DBF with morphological processing. From the results, we can see that the DBF method with morphological processing can preserve the moving object area very well and eliminate the background interference completely. The result of this processing can be very helpful for the further motion area detection.


After applying the step of DBF method with morphological processing, the optical flow information of the background interference should be eliminated and only the optical flow information of real moving object is left. During the experimental test, we find that the appearance of a moving object can make a big influence on the instantaneous rate of change between the foreground motion information and the accumulative background optical flow information. In this paper, we use the result of DBF method with morphological processing as the foreground motion information FM. Because the result of DBF method with morphological processing comes from the last three frames accumulative optical flow information so that the result of the first seven frames accumulative optical flow information is used as the accumulative background optical flow information ABOF7. So we can define the instantaneous rate of change for the moving object appearance IRCA as follows:

From the results, we can see that, for the background without moving object, IRCA has a small value with little changing. But if there is moving object appearance, the value of IRCA will increase sharply and last for several frames time. By taking advantage of this feature, we can use this IRCA value to detect the movement of moving object and give the alarm without delay. In our experiment, the alarm threshold T is set as 0.25 and the abnormity alarm will occur whenever the IRCA value is above T. It can be described as follows:



A video monitoring & detection system was thus developed successfully in this paper. This system mainly provides an efficient method for surveillance purposes and is aimed to be highly beneficial for any person or organization. Thus, a motion based change detection in avi video format was completed and successfully implemented.


  • Expert Systems
  • Home Security Systems
  • Industrial Security Systems
  • Airports
  • Government Buildings
  • Research Facilities
  • Military Facilities
  • Medical Imaging
  • Artificial Intelligence
  • Micro Robots
  • Machine Vision Applications

Future Scope:

The future scope of the work done could be as follows: the due course of time as we started to understand the minute details of our work, we significantly realized that our software would be tremendously important in the future world.

Following changes or additions can be done to include some new features:

  • With the existing alarm system, advancement can be included and SMS can be sent to the user when motion is detected.
  • The stored video can be automatically transferred to some email account so that an extra backup data can be used.
  • A user_id and password can be given to a user so that unauthorized people don't have access to the software.
  • A facility for the user can be given where he can mainly monitor only a small specific area in the range of the Web cam.
  • In the future, the user can be provided a remote access to this software from some remote PC through internet.
  • Include an option to take snaps periodically, manually or automatically.
  • Work could be done to make the system more users friendly for a layman user.


  1. Duane C. Hanselman and Bruce L. Littlefield, "Mastering Matlab 7".
  4. Rozinet, O. and Z. Szabo, "Hand motion detection using Matlab software environment".
  5. Nehme, M.A.; Khoury, W.; Yameen, B.; Al-Alaoui, M.A., "Real time color based motion detection and tracking", Proc. ISSPIT 2003, 3rd IEEE International Symposium on Signal Processing and Information Technology, 2003, 14-17 Dec. 2003, pp. 696 - 700, 14-17 Dec. 2003.
  6. Josué A. Hernández-García, Héctor Pérez-Meana and Mariko Nakano-Miyatake, "Video Motion Detection Using the Algorithm of Discrimination and the Hamming Distance", Lecture Notes in Computer Science, Springer-Verlag, Germany.
  7. H.A.M. El_Salamony, H.F. Ali, and A.A. Darweesh, "3D Human Body Motion Detection and Tracking in Video", Proc. Acta Press.
  8. Song, Y.,"A perceptual approach to human motion detection and labeling", PhD thesis, California Institute of Technology, 2003.
  9. Yilmaz, A., M. Shah, "Contour Based Object Tracking with Occlusion Handling in Video Acquired Using Mobile Cameras", Proc. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2005.
  10. Borst, A. and Egelhaaf, M., "Principles of visual motion detection", Trends in Neurocience, Vol. 12, pp. 297-305, 1989.
  11. Y.L. Tian and A. Hampapur, "Robust Salient Motion Detection with Complex Background for Real-time Video Surveillance," IEEE Computer Society Workshop on Motion and Video Computing, Breckenridge, Colorado, January 5 and 6, 2005.
  12. C. Bahlmann, Y. Zhu, Y. Ramesh, M. Pellkofer, T. Koehler, "A system for traffic sign detection, tracking, and recognition using color, shape, and motion information," IEEE Intelligent Vehicles Symposium, Proceedings,2005, pp. 255-260.
  13. A. Manzanera and J.C. Richefeu, "A new motion detection algorithm based on background estimation," Pattern Recognition Letters, vol. 28, n 3, Feb 1, 2007, pp. 320-328.
  14. Y, Ren, C.S. Chua and Y.K. Ho, "Motion detection with nonstationary background," Machine Vision and Applications, vol. 13, n 5-6, March, 2003, pp. 332-343.
  15. J. Guo, D. Rajan and E.S. Chng, "Motion detection with adaptive background and dynamic thresholds," 2005 Fifth International Conference on Information, Communications and Signal Processing, 06-09 Dec. 2005, pp. 41-45.
  16. A. Elnagar and A. Basu, "Motion detection using background constraints," Pattern Recognition, vol. 28, n 10, Oct, 1995, pp. 1537-1554.
  17. J.F. Vazquez, M. Mazo, J.L. Lazaro, C.A. Luna, J. Urefla, J.J. Garcia and E. Guillan, "Adaptive threshold for motion detection in outdoor environment using computer vision," Proceedings of the IEEE International Symposium on Industrial Electronics, 2005. ISIE 2005,vol. 3, 20-23 June 2005, pp. 1233-1237.
  18. P. Spagnolo, T. D'Orazio, M. Leo and A. Distante, "Advances in background updating and shadow removing for motion detection algorithms," Lecture Notes in Computer Science, vol. 3691 LNCS, 2005, pp. 398-406.
  19. D.E. Butler, V.M. Bove Jr. and S. Sridharan, "Real-time adaptive foreground/background segmentation," Eurasip Journal on Applied Signal Processing, vol. 2005, n 14, Aug 11, 2005, pp. 2292-2304.
  20. Y.S. Choi, Z.J. Piao, S.W. Kim, T.H. Kim and C.B. Park, "Salient motion information detection technique using weighted subtraction image and motion vector," Proceedings of 2006 International Conference on Hybrid Information Technology, vol. 1, 2006, pp. 263-269.
  21. J.W. Wu and M. Trivedi, "Performance characterization for Gaussian mixture model based motion detection algorithms," Proceedings of International Conference on Image Processing, vol. 1, 2005, pp. 1097-1100.
  22. P.R.R. Hasanzadeh, A. Shahmirzaie and A.H. Rezaie, "Motion detection using differential histogram equalization," Proceedings of the Fifth IEEE International Symposium on Signal Processing and Information Technology, 2005, pp. 186-190.
  23. D.X. Zhou and H. Zhang, "Modified GMM background modeling and optical flow for detection of moving objects," Conference Proceedings of IEEE International Conference on Systems, Man and Cybernetics, vol. 3, 2005, pp. 2224-2229.
  24. G. Jing, C.E. Siong and D. Rajan, "Foreground motion detection by difference-based spatial temporal entropy image," IEEE Region 10 Conference Proceedings: Analog and Digital Techniques in Electrical Engineering, 2004, pp. 379-382.
  25. C.C. Chang, T.L. Chia and C.K. Yang, "Modified temporal difference method for change detection," Optical Engineering, vol. 44, n 2, February, 2005.
  26. J. Lopez, M. Markel, N. Siddiqi, G. Gebert and J. Evers, "Performance of passive ranging from image flow," IEEE International Conference on Image Processing, vol. 1, 2003, pp. 929-932.
  27. N. Lu, J.H. Wang, Q.H. Wu and L. Yang, "Motion detection based on accumulative optical flow and double background filtering," Proceedings of World Congress on Engineering, London, UK, 2-4 July, 2007, pp. 602-607.
  28. J. Lin, J.H. Xu, W. Cong, L.L. Zhou and H. Yu, "Research on real-time detection of moving target using gradient optical flow," IEEE International Conference on Mechatronics and Automation, 2005, pp. 1796-1801.
  29. E. Trucco, T. Tommasini and V, Roberto, "Near-recursive optical flow from weighted image differences," IEEE Transactions on Systems, Man, and Cybernetics, Part B: Cybernetics, vol. 35, n 1, February, 2005, pp.124-129.
  30. H. Ishiyama, T. Okatani and K. Dequchi, "High-speed and high-precision optical flow detection for real-time motion segmentation, " Proceedings of the SICE Annual Conference, 2004, pp. 751-754.
  31. L. Wixson, "Detecting salient motion by accumulating directionally-consistent flow," IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 22, issue 8, Aug. 2000, pp. 774-780.
  32. J. Barron, D. Fleet and S. Beauchemin, "Performance of Optical Flow Techniques," International Journal of Computer Vision, vol. 12, n 1, 1994, pp. 42-77.
  33. H. Liu, T. Hong, M. Herman and R. Chellappa, "Accuracy vs. Efficiency Trade-offs in Optical Flow Algorithms," In the Proceeding of Europe Conference Of Computer Vision, 1996.
  34. B. Galvin, B. McCane, K. Novins, D. Mason, and S.Mills, "Recovering Motion Fields: An Evaluation of Eight Optical Flow Algorithms," In Proc. Of the 9th British Machine Vision Conference (BMVC'98), vol. 1, Sep. 1998, pp. 195-204.
  35. Wikipedia, the free encyclopedia. 20 February 2007. Lucas Kanade method. Available:
  36. Y. Shan and R.S. Wang, "Improved algorithms for motion detection and tracking," Optical Engineering, vol. 45, n 6, June 2006.
  37. H.J. Elias, O.U. Carlos and S. Jesus, "Detected motion classification with a double-background and a neighborhood-based difference," Pattern Recognition Letters, vol. 24, n 12, August, 2003, pp.2079-2092.
  38. J. Zheng, B. Li, B. Zhou and W. Li, "Fast motion detection based on accumulative optical flow and double background model," Lecture Notes in Computer Science, Computational Intelligence and Security - International Conference, CIS 2005, Proceedings, vol. 3802 LNAI,2005, pp. 291-296.
  39. R.C. Gonzalez and R.E. Woods, Digital Image Processing, Prentice-Hall, December, 2002, Second edition, ISBN: 0130946508.