Motion Detector using a WebCam and Python

Poulami Ghosh
3 min readJul 7, 2020

--

The topic of the project is “Motion Detection Application Using Web Camera”. From the topic, everyone may know that the target of the project is using “web camera” to achieve the target of “motion detection”. It is developed from a security point of view. The objective of this project is to develop a system that monitors the area in which it is being implemented. It is applicable in the area where no one is permissible to enter, also where we need to detect if any motion has been done. We may be able to perform the following tasks using this application, though the list is non-exhaustive: Find in front of screen time of your employee during working from home, Monitor your child’s in front of screentime during your busy schedule, Locate unwanted public/animal movements around your room/house and what not!

Keywords -Image capturing, motion detection, monitoring, security.

Hardware Requirements- A computer with a webcam or any type of camera installed.

Software Requirements- Python 3 or above.

Security is one of the most important problems all over the world. This project basically concerns the use of motion detection applications using webcams for security purposes. Today in our society security is one of the major issues and having a 24*7 human eye is just impossible.

This project Motion Detection Application Using Web Camera is just one of the applications which help us to achieve this goal. In order to be secured of safety, it is useful to realize and manage a smart surveillance system combined with image processing techniques.

Algorithm-

To start the basic installations, we will have to install python 3 or above, pandas, and OpenCV via pip install. The algorithm of my project looks like-

STEP 1: Import required libraries

STEP 2: Initialize variables, lists, data frames

STEP 3: Capture the video frames using a webcam

STEP 4: Converting the captured frame to gray-scale and applying Gaussian Blur to remove noise

STEP 5: Capturing only the first gray frame

STEP 6: Creating a Delta Frame and a Threshold Frame

STEP 7: Dilating the Threshold Frame and finding pixel contours in it

STEP 8: Finding the contour area and bounding the end-points in a rectangle

STEP 9: Capturing the time-stamp when objects enter and exit the frame

STEP 10: Displaying all the different frames

STEP 11: Generating the Time Data

Python Code-

Till now, all timestamps are stored in the pandas data-frame. To get insights from the data generated, we will export our data-frame onto a CSV file at our local disk.

This is how the generated CSV looks like. As you can see, there that object has been detected 2times till the program has been ended. You can see the start and end time and calculate the time when the object was in front of the camera.

I have shared a demo video of my project, you can check it out before starting your own motion detection project!

This project has an infinite number of future scopes. Some of them are..

1. Internet-Of-Things enthusiasts can even deploy this program on a Raspberry-Pi server and do wonders!

2. Machine learning enthusiasts can use artificial neural networking and detect the object type as in human, animals etc.

3. In the proposed method, the background subtraction technique has been used that is simple and fast. This technique is applicable where there is no movement of the camera. For robotic applications or automated vehicle assistance systems, due to the movement of the camera, backgrounds are continuously changing leading to the implementation of some different segmentation techniques like single Gaussian mixture or multiple Gaussian mixture models.

Isn’t this exciting? when we think about coding, we immediately think that it’s gonna be boring, tough, and tiresome! But with this one, you can do all sorts of fun stuff!

hasta la vista until next time!

--

--

Poulami Ghosh

Software Developer @ThoughtWorks .Thinker. Reader. Developer.