Motion Detection of Webcam Using Frame Differencing Method
Pooja Nagpal, Shalini Bhaskar Bajaj, Aman Jatain, Sarika Chaudhary
Department of Computer Science, Amity University, Gurugram, India.
*Corresponding Author E-mail: pbnagpal@ggn.amity.edu
ABSTRACT:
It is the capability of humans and as well as vehicles to automatically detect object level motion that results into collision less navigation and also provides sense of situation. This paper presents a technique for secure object level motion detection which yields more accurate results. To achieve this, python code has been used along with various machine learning libraries. The detection algorithm uses the advantage of background subtraction and fed in data to detect even the slightest movement this system makes use of a webcam to scan a premise and detect movement of any sort; on the recognition of any activity it immediately sends an alert message to the owner of the system via mail. Any person requiring a surveillance system can use it.
KEYWORDS: Motion Detection, OpenCV, Background Subtraction, SMTP Library.
INTRODUCTION:
Formally, Motion Detection refers to the recognition of any kind of activity in the vicinity of an installed security system. In other words, a camera is used to capture any sort of activity in a susceptible environment. Motion detection is usually a software-based monitoring algorithm which, when motion is detected signals the surveillance camera to begin capturing the event, also called activity recognition. Though, an advanced motion detecting security system can analyse the kind of motion and verify it to check if it deserves an alert. This paper on the other hand proposes a system that can detect even the slightest motion and alert the owner of the security system regardless of the severity, it has aimed to create a highly sensitive system.
OpenCV: Open Source Computer Vision, OpenCV in short, is a library that is primarily used for real-time computer vision. It aims at providing computer vision for machines to decipher an image as humans naturally do which basically makes it a target when it comes to the concept of Machine Learning and Artificial Intelligence. Open CV was originally developed by Intel and later supported by others. The library is cross-platform and permitted for use under the open-source license. It fascinatingly also supports deep learning frameworks, like TensorFlow, Torch/PyTorch and Caffe, again a field of vast exploration 1. One of the disadvantages of using OpenCV is that it can only be deployed locally, and extending it to the web or having a server-side execution is a challenge that does not need immediate dealing.
LITERATURE REVIEW:
As technology has been on the up-rise people have started taking the view of reducing the trouble of having to install or recruit security in the system which they consider susceptible. Security systems which can detect any sort of activity, is the need of the hour. For one, it reduces the stress of the owner; another reason could be to reduce the burden of security guards also, if a person has trust issues that keep her/him awake, this system is certain to help her/him rest well. A security system that can motion detection is not a brand-new concept. In the past many project of similar kind have been constructed and been used efficiently.
A. Motivation and present state of Research:
The various methods today being used for image and video processing are Frame differencing, Optical flow and Background subtraction. To detect the moving objects the Frame differencing method uses subtraction of successive frames, the same way a comparison is done, which help identify what in the background or frame has changed, within the few milliseconds that the difference is identified, the frame is declared as the proof of movement or intrusion. As well there are cascade classifiers which can be converged with either background subtraction or with optical flow 2. This approach is straightforward to implement and easily adaptable to dynamic environments, but it cannot always extract the complete edges of the object.
One of the other popular techniques is the optical flow method 2. This method has two steps. First finding the image optical flow, which is simply the movement or shift of individual pixels on the target image plane, and then performing grouping process with the obtained optical flow features. It performs accurately well in the detection process but the shortcoming is the increased number of calculations. The third method is background subtraction 3. The principle that is used in background subtraction algorithm, is to model a background something similar to how a green screen works, and compare it with the current frame to detect objects i.e., zones where significant changes occur 4, 5. This leads the background subtraction algorithm to detach the moving objects i.e., the foreground part, from the static part of the frame i.e., the background.
B. Proposed Webcam Motion Detection System:
This paper puts forward the idea of using Background Subtraction, also known as Foreground Detection; wherein Gaussian Mixture-based Background / Foreground Segmentation Algorithm (MOG2) is applied 6. The algorithm is fed into a texture separator to further find contours, in this way it incorporates the frame differencing method. On the recognition of contours, the webcam is potentially sensitized to the movement, making it successful in noting an intruder within the possible pixel range of any camera that the algorithm is deployed on.
This paper suggests, a program that will detect the motion using open-cv and python and notify the owner about the activity through a mail using Gmail, in this case particularly. The video will be captured with the help of web camera. The program will also click some pictures of the activity and send a picture with an alert mail as attachment to the mail id of the owner provided. The other pictures of the activity are stored in a folder in the system on which the program is executing.
Figure 1: Use Case Diagram for Proposed System
Methods of Motion Detection:
a) Frame Differencing:
In the technique of Frame Differencing, the computer / camera compares the pixels of the images in two consecutive frames. The motion detection system is alerted the moment a shift in the pixel positions is recognized. This method is not vastly used in terms of security systems, though it is on the rise with many researchers working it out. The objective of the approach is to detect the moving objects from the difference between the existing frame and the reference frame. The frame difference method is the common method of motion detection. This method adopts pixel-based difference to find the moving object 7.
Figure 2: Frame Differencing Example 8
b) Optical Flow:
Optical flow is the outline of apparent motion of image objects between two successive frames caused by the movement of object or camera. It is a two-dimensional vector field where each vector is a displacement vector showing the shifting of points from first frame to second [9][10]. This technique also makes the use of OpenCV. This method has an extension called Lucas-Kanade, which offers a set of equivalences and variables which can help derive the algorithm working in the motion detector making it a potentially better way of object detection.
Figure 3: Example for Optical Flow 11
c) Background Subtraction:
Background subtraction is a common and widely used technique for generating a foreground mask (namely, a binary image containing the pixels belonging to moving objects in the scene) by using static cameras [12]. This method requires two major tasks: one, the initialization and two, the update. The basic task is to subtract the background in the process of extracting the foreground, by performing subtraction in the current frame. Compared to all the other motion detection techniques, this one is preferred the most in terms of use and effectiveness. The steps undertaken in the background subtraction method is as follows:
1. Train the algorithm to recognize movement by applying a cascade classifier.
2. Using the OpenCV module, cv2, import the background subtraction module, MOG2 in this case.
3. Apply the frame differencing method and loop the algorithm to run the same way.
Figure 4: Background Subtraction Example 13
MOG Background Reduction:
Background subtraction is a major pre-processing step in many vision-based applications. For example, consider the cases like visitor counter where a static camera takes the number of visitors entering or leaving the room, or a traffic camera extracting information about the vehicles etc. In all these cases, first you need to extract the person or vehicles alone. Technically, you need to extract the moving foreground from static background, doing so helps in determining if there exists some movement that is worth noticing.
Mixture of Gaussian: The idea here is to extract the moving foreground from the static background. One can also use this to compare two similar images, and immediately extract the differences between them 14. One important feature of this algorithm is that it selects the appropriate number of gaussian distribution for each pixel. It provides better adaptability to varying scenes due illumination changes etc 15.
Figure 5: Activity Diagram for Proposed System
Experimental Results:
The method used in this paper is background subtraction. The experiment results have been satisfactory as the system has the user notified on the detection of motion.
The interface for a user to get configured has been created. When the tracking begins and the vicinity is without activity, the webcam does not do much, the moment activity is detected, and it creates red coloured rectangles around the moving object. This is followed by the capturing of the pictures and sending a mail to the configured user.
Figure 6: Motion Detector without Activity
Figure 7: Motion Detector with Activity
Figure 8: Alert Mail Received by the User
Table I Motion Detection Time Of Proposed And Other Methods
Techniques |
DSO |
GPP |
BS |
FD & BS |
Time in Sec |
0.4 |
2.0 |
2.7 |
0.8 |
Table 1 presents the comparable results of various approaches. DSO approach provides better results than the frame differencing and background subtraction approach, the one discussed in this paper, but DSO has its own limitations which are covered by over here. For instance, sequential frame convergence or the user interface and frequency of use.
Table II Motion Detection Accuracy
Image Background |
Accuracy |
Less Motion |
0.97 |
Intermediate Motion |
0.89 |
Heavy Motion |
0.80 |
Table 2 shows accuracy measures of the proposed approach. It is quite obvious that all three forms of fluctuation are easily determined by the background subtraction and frame differencing.
Conclusion and Future Work:
The interface for a user to get configured has been created. When the tracking begins and the vicinity is without activity, the webcam does not do much, the moment activity is detected, and it creates red coloured rectangles around the moving object. This is followed by the capturing of the pictures and sending a mail to the configured user. The Foreground Extraction done using Webcam has been a success. The alert mail via SMTP Library, sent to the configured user has been a success. The system has been successful in saving the images captured of the motion detected. Finally, there is the accuracy score hitting 0.97 with a minimum of 0.80 Motion Detection in Security Systems is a blooming concept. But there is still much to uncover. Some of the aspects of motion detection are not optimal, and with changing technology in a fast paced and impatient world, AI can look forward to heights that now seem unattainable. The future scope of this paper ranges from being able to classify whether the object detected is stationary or moving or maybe from what the object detected by the webcam is; all the way to being able to define how hostile the detected object is and whether it poses a threat to the security system or even to another human being.
REFERENCES:
1. Mahamkali, Naveenkumar & Vadivel, A. (2015). OpenCV for Computer Vision Applications. Conference: Proceedings of National Conference on Big Data and Cloud Computing (NCBDC’15), March 20, 2015At: Trichy Project: Human Action Recognition.
2. P.Gao, X.J. Sun, and W. Wang. Moving object detection based on kirsch operator combined with optical flow. In International Conference on Image Analysis and Signal Processing, pages 620–624, April 2010.
3. Rupalli S.Rakibe and Bharati D.Patil. 2013. Background subtraction Algorithm based Human motion detection. International Journal of scientific and research publications.
4. Joshan.J Athanesious and Suresh .P.2012.Systematic survey on Object Tracking Methods in Video. International Journal of Advanced Research in Computer Engineering and Technology.
5. Sen Ching S. and Chandrika Kamath.2011.Robust Techniques for background subtraction in urban Traffic Video.
6. Zivkovic, Zoran & Van der Heijden, F.. (2006). Efficient adaptive density estimation per image pixel for the task of background subtraction. Pattern Recognition Letters. 27. 773-780. 10.1016/j.patrec.2005.11.005.
7. D.Venkata Siva Prasad1; Ch.Niharika2; R. Vishwaja3; R.Srinidhi;4A.Preethi.5 Object Detection and Tracking using Image Processing. IJCRT_194371
8. SamLow. Ball-Tracking for Amateur Sports. A CS Project from Bristol, UK. squawkfly.wordpress.com/2015/05/31/frame-differencing/
9. Abhishek Kumar Chauhan and Prashant Krishan. 2013.Moving Object Tracking Using Gaussian Mixture model and Optical flow. International Journal of Advanced Research in Computer science and Research Engineering.
10. M.P. Patel and S.K. Parmar. Moving object detection with moving background using optic flow. In Recent Advances and Innovations in Engineering (ICRAIE), pages 1–6, May 2014.
11. Lucas-Kanade method. Optical Flow. Lucas-Kanade Optical Flow in OpenCV. opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html
12. Z. Zivkovic, "Improved adaptive Gaussian mixture model for background subtraction," Proceedings of the 17th International Conference on Pattern Recognition, 2004. ICPR 2004., Cambridge, 2004, pp. 28-31 Vol.2, doi: 10.1109/ICPR.2004.1333992.
13. Background Subtraction using open computer vision. opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html#:~:text=Background%20subtraction%20is%20a%20major,information%20about%20the%20vehicles%20etc.
14. Ruolin Zhang and Jian Ding.2012.Object Tracking and Detecting based on Adaptive Background Subtraction. International Workshop on Information and Electronics Engineering.
15. C. S. Royden and K.D. Moore. Use of speed cues in the detection of moving objects by moving observers. Vision Research, 59(0):17 – 24, 2012
Received on 12.05.2021 Accepted on 31.05.2021 ©A&V Publications all right reserved Research J. Engineering and Tech. 2021;12(2):32-38. DOI: 10.52711/2321-581X.2021.00006 |
|