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!
  • can't process. time to shut off.
    bitchwhocodes, 01:31:14 - Mar 11
  • In good company : http://bit.ly/99xfbt . I think I've seen everyone on this list, at least once in the past 6 years. #flashbelt
    scottjanousek, 01:19:49 - Mar 11
  • #FFK10 conference schedule online: http://is.gd/aayW8
    flashforum, 01:17:43 - Mar 11
  • Ace video about the graphic design of the bodywork on classic 70's Le Mans racing cars http://www.gestalten.com/motion/clipHiRes?id=122
    robmccardle, 01:15:22 - Mar 11
  • RT @AdobePRCanada: Find out the latest on Creative Suite @csbuzz.adobe.com join #csbuzz&your chance to win FITC Toronto party tix
    FITC, 01:00:07 - Mar 11
  • RT @motodev A sea of mobile devices session at #gdc http://flic.kr/p/7JVjrU<- from my fitc 2005 preso http://bit.ly/bjkSKW more true now :)
    scottjanousek, 00:54:26 - Mar 11