Motion Detection Using Raspberry Pi


Introduction: Motion Detection Using Raspberry Pi

Here i am explaining a simple motion detection project. Platform used is raspberry pi. Motion is detected using the simplecv libraries in python.

What is SimpleCV ?
SimpleCV is an open source framework for building computer vision applications. With it, you get access to several high-powered computer vision libraries such as OpenCV – without having to first learn about bit depths, file formats, color spaces, buffer management, eigenvalues, or matrix versus bitmap storage.

Step 1:

Parts needed

1.Raspberry pi

2.USB Camera

Now we can see how the motion is detected using the camera. By taking multiple images and subtracting their pixel matrix. If their is no motion, the difference between the images will be almost equal to zero or a small value. Otherwise if motion detected, their will be a particular big value for the difference matrix. This is the basic idea behind the motion detection.

The python code for motion detection is given below

from SimpleCV import Camera,Display
import time
cam=Camera() //Intializing camera
time.sleep(3) //delay for three seconds
a=cam.getImage()//capturing the first image
b=cam.getImage()//capturing the second image after one second
d=b-a //subtracting the image pixels // display the subtracted image
mat=d.getNumpy() //converting to numpy array
avg=mat.mean() //take the mean
print avg //print average value on the screen
if avg>6:
print("Motion Detected")
else: print("not detected")



    • Make it Move Contest

      Make it Move Contest
    • Planter Challenge

      Planter Challenge
    • Oil Contest

      Oil Contest

    We have a be nice policy.
    Please be positive and constructive.




    Nice job! The Raspberry Pi is amazing! :D

    Going to try soon.


    1 reply