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

Twitter

  • Let's meet on Twitter!
  • my @ignitesalem preso is up! http://bit.ly/18MarD
    phillip, 04:29:23 - Jul 04
  • Played 18 at The Ranches but there was no GPS support to test out Golfshot app.
    paulm, 03:46:04 - Jul 04
  • What Did Shaq Just Tweet? A New Web Site Knows http://tinyurl.com/nbsckw
    techxav, 03:19:46 - Jul 04
  • Internet Companies and Ad Agencies Go From Old Enemies to New Friends http://tinyurl.com/n6zabq
    techxav, 03:19:43 - Jul 04
  • Woman Shot in Apple Store at Clarendon's Market Common http://bit.ly/hUt9N
    techxav, 03:16:10 - Jul 04
  • 25 Brilliant Bookmarklets to Boost Your Browsing http://bit.ly/RIbi2
    techxav, 03:07:00 - Jul 04
  • 8 - 0 giants at the bottom of the 2nd. When does the mercy rule kick in?
    johnwfisherii, 02:56:59 - Jul 04