Motion detector using Computer vision

Published on . Written by

Motion Detection using Computer Vision
The need for security systems is rising all over the world due to an increase in crimes being committed. As the public gets more and more aware of the dangers around them, they become more willing to spend money on surveillance equipment. Not only does surveillance equipment help you keep track of what’s happening at home while you are away at the office, but it also allows you to gather evidence in case something goes wrong.

Read more..
Nowadays we find cases wherein such cameras provide crucial evidence to help in capturing and sentencing thieves and robbers. So how do we combine a love for coding and your need for a security system? Well, this OpenCV project helps you build a simple motion detector camera which works like a surveillance camera using the most simple concepts.


Skyfi Labs Projects
Project Description

Motion detectors find large-scale applications in a wide variety of areas. This includes everything from security systems to helping robots and other autonomous systems move and interact with the environment. If you have noticed, even the hand-drying system used in most washrooms, make use of a motion detector or proximity switch to get triggered and power on and off. Certain cameras now only start recording when they detect motion within a specified range, this helps cameras save battery and prevents the wastage of storage data, helping to increase the efficiency of the security system. In this project, we will attempt to design and build a sample OpenCV algorithm or interface that links with a camera and helps with motion detection.

Concepts Used

  • Fundamentals of programming
  • Python Programming
  • Algorithm Logic
  • OpenCV
  • Data segmentation
  • Edge Detection
  • Feature Extraction
  • Background Subtraction
Hardware and Software Requirement

  1. A device that runs on a suitable OS such as Windows/Linux/Mac
  2. Enough storage on hard disk to store the database
  3. Enough memory to run the program
  4. OpenCV installed
  5. Python 2 installed
  6. Required libraries of code- Numpy, imutils, and cv2
Project Implementation

  • Motion detection used the principle of background subtraction to essentially detect motion. Background subtraction is an integral part of any image processing program, as it allows the system to count the number of objects passing through the frame, and also aids with motion detection.
  • Motion detection may be implemented via two methods: Gaussian Model-based segmentation and Bayesian probability-based segmentation.
  • Both these methods start by segmenting the data from the foreground and background of the image, helping the system analyse the image and figure out what’s happening.
  • The most basic assumption we make while building a motion detection system is that the background remains more or less static over consecutive frames, helping us model it such that it may be monitored for changes.
  • However, this assumption causes problems when it comes to real world application such as external factors such as lighting, shadowing and reflections can change the way the background looks in each frame.
  • To start with, import the libraries you need such as Numpy, imutils and cv2.
  • Next, parse the data coming into the system, and send in path files to the video stream from a normal Raspberry Pi camera or video recorder.
  • In case you don’t input a path file, OpenCV will make use of your webcam to track motion.
  • Define a minimum area function that filters out small changes in the background caused due to external factors.
  • Now grab the first frame of your video and start modeling it.
  • Scale the frame, convert to grayscale and apply Gaussian filters to smooth the image. When the first frame has been modelled, use it as a template to compare and study the subsequent frames in the video stream.
  • Use the function frameDelta that compares pixel intensity values to understand where they have been major changes in the background and foreground images.
  • Apply contour and edge detection techniques to plot this figure or change in background and you will obtain the outline of the moving person.
  • Any changes between frames will be detected as motion, and your surveillance camera is good to go.
Kit required to develop Motion detector using Computer vision:
Technologies you will learn by working on Motion detector using Computer vision:


Any Questions?


Subscribe for more project ideas