Adjazent | Alan Ross


Simple Webcam motion detection using bitmaps and filters

Simple Webcam motion detection After playing around with blob detection and somehow not getting it fast enough a neat little solution came up from Emil Korngold. Using the built in Adobe function ‘getColorBoundsRect’ for the BitmapData object is so much faster looking for ‘Blobs’. (Thanks! I had a look at that when starting and then forgot all about it. Sometimes the simple things are just too far away).
To get a usable result when detecting motion it is good to apply filters and thresholds. This reduces noise and errors when looking for the bounds of a given color.  This example is based on the ‘Focus’ demo files provided by Papervision3D.

Click here to have a look at the result. Enjoy!

The interesting part of the code:

private function loop(e:Event):void
{
	//bitmap containing difference between last & this frame
 	newBmd.draw(input);
 	newBmd.applyFilter(newBmd,bounds,topLeft,filter);
 	newBmd.draw(oldBmd,null,null,BlendMode.DIFFERENCE);
 	newBmd.threshold(newBmd,bounds,topLeft,">",0xFFAAAAAA,0xFFFFFFFF);	//remember bitmap for next time round
 	oldBmd.draw(input);
 	oldBmd.applyFilter(oldBmd,bounds,topLeft,filter);
 	//now get bounds of a given color...
 	var newBound:Rectangle = newBmd.getColorBoundsRect(m,c,true);
	//now use the newBound to move something...
}

Hope this is of any use to someone…

3 Comments. Leave a comment too

Nice work mate. Runs smooth.
I like the fact that you don’t have to do a selection first, and think I’ll rework mine to achieve the same. Thanks!


Hi. Great blog. This is fantastic. I do quite a lot of stuff with webcams and motion detection. I’ll definitely use this at some stage. Don’t worry though, I’ll link back to you. :)


well it will me fantastic for look an object around … :)
just moving the head.


Trackbacks. Ping Adjazent now.

Say what you think:

Popular

Subscribe

Meta

Twitter

  • Let's meet on Twitter!
  • planning a lil industry pre-fitc mixer for the Ottawa peeps , good opp to network for the students :)
    bitchwhocodes, 21:31:08 - Mar 11
  • Thanks to sponsors #Flashbelt Conference announces STUDENT RATE for WORKSHOPS -Tell the students! http://tinyurl.com/yatdt6l
    flashbelt, 21:30:21 - Mar 11
  • If you're going to FITC Toronto 2010 then be sure to join the community group at http://community.fitc.ca/group/attendeesoffitctoronto2010
    FITC, 21:30:10 - Mar 11
  • RT @pixelbender: just found out about @Adobe_Care for official Adobe support, very cool.
    mesh, 21:27:44 - Mar 11
  • OMG. Waarom kunnen sites over #usability niet eens een keeróók prettig voor het oog zijn?! http://bit.ly/dq0DqS
    stutger, 21:22:54 - Mar 11
  • Good deal :)
    rhall, 21:22:24 - Mar 11
  • iPhone OS 4.0 Looms, But When Will We See It? - http://tcrn.ch/aJLgWZ by @parislemon
    TechCrunch, 21:16:58 - Mar 11