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.

Popular

Subscribe

Meta