Intro: 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 which is available 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.
Now we can see how the motion is detected using the camera. Take multiple images and subtracting each image from the previous one. If their is no motion, the difference between the images will be almost equal to zero or a small value. Otherwise if motion detected, the difference is a big value. This is the basic idea behind the motion detection.
The python code for motion detection is given below
from SimpleCV import Camera,Display
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
d.show() // 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
else: print("not detected")