Your Face, My Head: Webcam and Papervision Demo (with source, eventually)

Paperhead!I wanted to see just how difficult rigging up one of these would be. Found a good COLLADA file on the internet and I think it looks real purty (though I couldn’t say the same about the subject). Anyway if you have a webcam check it out! It’s fun.

Make sure to line your face up with the guide, and then click the red rectangle in the upper left hand corner. Wait a bit, and surprise!

I’ll be putting an instructional post up soon, documenting every last step 😉

Papervision Webcam Head

Who wins the award for most popular pixel?

From Soulwire, a snippet that gets the average color in an image:

function averageColour( source:BitmapData ):uint {
         var red:Number = 0;
         var green:Number = 0;
         var blue:Number = 0;

         var count:Number = 0;
         var pixel:Number;

         for (var x:int = 0; x < source.width; x++)
            for (var y:int = 0; y < source.height; y++)           {              pixel = source.getPixel(x, y);                     red += pixel >> 16 &amp; 0xFF;
               green += pixel >> 8 &amp; 0xFF;
               blue += pixel &amp; 0xFF;


         red /= count;
         green /= count;
         blue /= count;

         return red << 16 | green << 8 | blue;

Careful not to pass a BitmapData with transparent pixels to this function, because it will see those as black pixels and you will get a much darker color than you wanted.

Quick AS3 Webcam Capture Class

If you are feeling lazy and don’t want to look up exactly how to instantiate a webcam and use it to take a snapshot of the user… just download this and use like so. It also flips the image so the user is not completely disoriented.

The default camera size is 600 x 400, you can pass two optional params to the constructor to specify different dimensions.

var webcam:CamGrabber= new CamGrabber();
btnToPress.addEventListener(MouseEvent.CLICK, onPictureSnap, false, 0, true);

function onPictureSnap(e:MouseEvent):void{
      var userpic:Bitmap=new Bitmap(webcam.snap());

Get Adobe Flash player