Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Monitoring the Webcam

Monitoring the Webcam

To monitor changes in the video stream captured from the webcam, you need to take regular snapshots of the video object. I use setInterval to call a snapshot function every x milliseconds. Then, to actually determine whether there has been movement, at any moment in time two bitmaps have to be in memory—the bitmap created last time a snapshot was taken (“before”) and a bitmap containing the current state of the video (“now”). Using the BitmapData class you can then compare the two bitmaps:

import flash.geom.Matrix
import flash.display.BitmapData

now=new BitmapData(output_vid.width,output_vid.height);
m=new Matrix();

function snapshot()
//…… code that check's difference between 'now' and 'before'