This is a blog about Flash & AS by betaruce :-)



Calendar

September 2005
M T W T F S S
« Aug   Oct »
  1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30  

September 24, 2005

WebCam motion detection (simplified code)

Filed under: My Flash Programs, Using Flash — betaruce @ 4:52 pm

Guy Watson has a good article on Webcam motion detection. It makes good use of the new BitmapData methods and blendmode so the code can run pretty fast. His code is really impressive.

However the fla provided in that page is not the most ’simplified’ code and ppl who just started using Flash 8 may have some problems in understanding the code. Therefore I simplified the code a bit and the effect is just similar :)

The code is as follows. You can also download the fla here.

import flash.display.*;
import flash.geom.*;
cam = Camera.get();
vid.attachVideo(cam);
//
now = new BitmapData(cam.width, cam.height);
before = new BitmapData(cam.width, cam.height);
rect = new Rectangle(0, 0, cam.width, cam.height);
pt = new Point(0, 0);
//
onEnterFrame = function () {
// detect motion if user allow us to access the webcam
if (!cam.muted) {
now.draw(vid);
now.draw(before,new Matrix(),new ColorTransform(),’difference’);
now.threshold(now,rect,pt,’>',0xff111111,0xffff0000);
before.draw(vid);
}
};
_root.attachBitmap(now,10);

• • •

Powered by: WordPress • Template by: Priss

cheap phentermine phentermine site phentermine effects online phentermine phentermine prescription buy phentermine online phentermine alternatives phentermine deit pill cheap generic phentermine order phentermine online Clenbuterol Phentermine online pharmacy phentermine buy phentermine weight loss pill Cialis Comparison Viagra Cheap Viagra Online Prescription generic viagra sale viagra online viagra viagra pill discount sale viagra Generico Impotencia Viagra viagra sildenafil citrate Xanax Online xanax order xanax valium versus xanax levitra order levitra levitra Online buy levitra cialis viagra levitra