Saturday, October 07, 2006

Motion Detection

CamCapture was working perfectly and was uploading every picture it took to the internet. However, this feature was slowly becoming very annoying. CamCapture took pictures at fixed intervals of time, and most of the pictures had nothing but an empty room! It uploaded hundreds of picture of an empty room and bombarded my email account with useless notifications. I wanted my application to take pictures only when someone entered my room. In other words, I had to make my program detect motion!

Well at first, I had no clue where to start. I had to spend several hours thinking of ways to detect motion. I found some very helpful articles on the Internet related to motion detection. After some research, I came up with an algorithm which detected motion by comparing each frame captured by the camera with the previous one. If the frames were more or less the same, fine, but if they had differences above a certain limit, the program would trigger a motion detection event. So, for every frame captured, I compared the pixels with the previous frame for brightness changes. If the brightness change of a certain pixel exceeded a tolerance limit, the program would increment a counter. At the end of the scan, it checked the value of the counter and if it exceeded a certain limit, it triggered a motion detection event. There was actually a time when I scanned each and every pixel for brightness changes. However, I quickly realized that it wasn’t a very good idea because scanning each pixel took several seconds, and time is a crucial factor for quick motion detection. So, after some experimentation, I decided to scan each frame diagonally and check only a limited number of pixels for changes. This reduced the scan time considerably. This algorithm works quite nicely. Now, I won’t have to delete several useless CamCapture notifications from my mail account because I only get notifications when something actually moves. :) Click here to see a snapshot of my motion detector. Before I created the actual motion detector, I created a motion analyzer for testing different algorithms. Click here to see a snapshot of the motion analyzer.

Reference:

28 comments:

Anonymous said...

hey man! found your site. ill try and get some pics scanned in and email em to you when i can. nice sunglasses

Anonymous said...

WELL DONE AND KEEP IT UP.

TIMULMAMA

Anonymous said...

Ashish, this is really great! that u r experimenting various ideas...keep this spirit always..
All the best!

Anonymous said...

hi ashish.. thats a wonderful program.. could you please mail me at "fiseye at gmail dot com".. i need some help for my project.. hope u do reply! :) thanks in advance

Anonymous said...

Hi ashish. I am really excited to find your website and see that you are doing something related to my project. I am currently trying to track multiple objects in a moving camera and I wonder whether you could mail me your source code to robinlee_1128 at yahoo.com.cn, so that I can learn sth. from you. Thank you very much!

Juan Antonio BreƱa Moral said...

Hi, I like your bot. I work with NXT lego mindstorm. I would like to use your motion detection algorithms, can you help me?

write me to bren[at]juanantonio.info
visit my webpage www.juanantonio.info or visit lejos.org

Unknown said...

HI THERE
I M WORKING ON A PROJECT ON COLOUR BASED OBJECT SENSING FOR FOR IMPARTING VISION TO MY ROBOT .. I M NEW TO PROGRAMMING . AN U PLEASE SEND ME THE SOURCE CODE OF THIS PROJECT OF URS TO HELP ME OUT .. PLS
MY EMAIL ID IS (kunalbhalla.1986@gmail.com)

Anonymous said...

hey man, nice work u doing there....
me jus starting from basics for robotics... had a difficult time trying to move a four wheel vehicle using pic micro controller... now after achieving that, i wish to go for webcam installed on robot... but before that i need to study motion detection. can u send me more info on ur work and the source files if poss... if u have any ideas to help me out, i would be very thankful... my email is ajay_karuna@hotmail.com

Anonymous said...


See some of my Flash webcam experiments & interactive samples on http://www.SillyWebcam.com .

pachinko27 said...

nice work... i'm really interested in your projects. i'm a beginer in VB6 programming and still studying. i'm interesred in your motion detection projects. i want to study your programs. could you please mail me the source code at pachinko27@gmail.com. thanx a lot.

Anonymous said...

erm how do u make windows apps? i am a very big beginner lol=] and i really like the self navigating viper robot ***** great work, even though i've no idea how to do it. is it c# or c++ or something???
do u know anything about java?

Anonymous said...

Awesome Project, Well Done!! Do you use VB 2005? If so, Would you like to send the sample project to my email (homeland_edelweiss@yahoo.com) I'm still newbie on webcam programming, especially on motion detector. Thx B4...

Unknown said...
This comment has been removed by the author.
Unknown said...

hi ashish.......i am trying to develop motion detection algorithm...but the problem is i am new to programming could you send me source code of this.....it will help me to understand better.....plz it is quit urgent plz help me on this...
my address is wajihazaidi@hotmail.com

Unknown said...

great work ashish and keep sharing

Regards
PM NG Mark

Anonymous said...

Dear Ashish , very nice project, im trying to start with soething similar , Could you send me the source code? it will be very appreciatted to start with
thanks , Gonzalo
info@ting.com

Anonymous said...

hi there..i have a project for motion tracking..(would like to track/detect the square/rectangular shape) using the opencv software...to compile the coding i must use the c++ coding with visual studio 2008 express edition...

but i don't know how to it done...

i ask for your help to do the coding for me to do the research and finish my project...

you can email me at
bagong_dmana2@yahoo.com

Anonymous said...

hye man, what do you think about tracking motion using webcam by opencv?do you have try opencv?

Anonymous said...

Dear Ashish , i'm also trying to develop the project related to motion detection for my study. it will be very appreciate if you can share the source code.

thanks , anis
aniswety2@gmail.com

Anonymous said...

hye dude, i have trying to use cprogramming n opencv for tracking motion using webcam.now, im stuck at the halfway.im succesfully added program for displaying webcam, displaying static object.but not about motion.can u help me?

ruelala23@yahoo.com

Anonymous said...

hi, it is really good idea..i m working on the same kind of project.. can u plz send me the code for reference?
My ID is: pradnyamahajan@ymail.com

Anonymous said...

hello...
did you use matlab for that project?
can you sent the source code for me?

my email : yohanes_yansen@yahoo.com

thanks before...

Arjun said...

Hi aashish, i am arjun from mysore... i have done same project but it is also capturing the images with no changes. can u pls mail me your code to mail id: reach2arjun@gmail.com

thank you

Kainat BAig said...

hi asheesh, i really like ur projct n m trying to do the same can u plz mail e source code of this project on my id, kainat_coolguy@hotmail.com
i'll be really thankful to u
regards
KAINAT

Unknown said...

Hi ashish. I am really excited to find your website and see that you are doing something related to my project. my name manjunath, i am doing my MSc in MSRSAS in bangalore, i am doing project on object detection and tracking in lacus kanade method. i have done object segmentation and detected the number of object in the number of frames, now i am facing problem in tracking. i am not able to put rectangular boundary across the segmentated part, so help me out in putting a rectangular box in the segmentated area.


thanking you,

Manjunath B

manjunath.o.b@gmail.com

Anonymous said...

Hey Ashish...Can you please email me the code for "Motion Detection" ?
I need a sensor code urgently.Please.

My email add is life21in@yahoo.com

Hrishikesh said...

hi Ashish,
This is Hrishikesh u r a great man m facing so many problems in my project my project is 'Motion Detection through webcam in java' i need ur help plz plz send me souce codde for it bt frnd m realy in hurry i dont have much time plz send me as much as posible...
my mail id is hrishikeshjadhav01@gmail.com

t said...

hi ashish.. that a wonderful program.. could you please mail me at "brandonblindsey@gmail.com".. i need some help for my project.. hope u reply! :) thanks in advance