Search This Blog

26 May 2011

Security system 2

OK, so this is the AS3 code we ended up using:


import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.KeyboardEvent;




var bandwidth:int = 0; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality. 


var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(320,240,30,false); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = -500;
video.y = -500;
addChild(video);


//This tells flash to detect a webcam and 
//attach its video feed to the stage
//(this particular feed is hidden outside the stage)


var bitmapData:BitmapData = new BitmapData(video.width,video.height);


var bitmap:Bitmap = new Bitmap(bitmapData);










stage.addEventListener(KeyboardEvent.KEY_DOWN, alarm);
function alarm(event:KeyboardEvent):void{
if (event.keyCode==74){

//This tells flash to 'listen' for a keyboard 
//command. If key 74 (j) is pressed, do the following:


bitmap.x = 119;
bitmap.y = 72;
bitmap.width = 320;
bitmap.height = 240;
addChild(bitmap);
bitmapData.draw(video);

// This tells flash to place a still image from 
//the video feed at the moment of the keyboard 
//command at the specified co-ordinates


var theDate:Date = new Date( );
var day = theDate.toLocaleDateString() // This tells flash to define the var 'date' by the computers RTC (real time clock)
var time = theDate.toLocaleTimeString()// This tells flash to define the var 'time' by the computers RTC


time_txt.text = time;
// This tells flash to input the time 
//as defined by the previous var statement 
//into the 'time_txt' object


day_txt.text = day;
// This tells flash to input the date 
//as defined by the previous var statement 
//into the 'day_txt' object
}
}




I've commented it out to make it easier to understand

Elliot made a background to go with this project.




So basically, our idea was to have the system to start capturing a video when a sensor was tripped and save it to 2 places after it has stopped recording an hour after the last sensor was tripped. However, without PHP and a online flash server, we cannot save the files. Also, Flash really doesn't like recording video. It requires each frame to be drawn into Bitmaps individually and then compiled and rendered into an animation.

Now we don't know PHP or have an online flash server or have to time to do either.

We settled with capturing an image from a video feed. When the SWF is open, it starts using the webcam just streaming a live feed to the stage, then when the sensor is activated, flash creates an image from the video feed and places it on the stage.

We cannot save these images so the only thing you can see is the last thing it saw. This is less than perfect but all we can do at this point.

0 comments:

Post a Comment