Tuesday, August 4, 2009

August 4th

Beginning to compare pixels today. Example being used is

import flash.display.Bitmap; import flash.display.BitmapData;  var bmd1:BitmapData = new BitmapData(50, 50, true, 0xFFFFAA00); var bmd2:BitmapData = new BitmapData(50, 50, true, 0xCCFFAA00); var diffBmpData:BitmapData = BitmapData(bmd1.compare(bmd2)); var diffValue:String = diffBmpData.getPixel32(1, 1).toString(16); trace (diffValue); // 33ffffff  var bm1:Bitmap = new Bitmap(bmd1); addChild(bm1); var bm2:Bitmap = new Bitmap(bmd2); addChild(bm2); bm2.x = 60;

http://livedocs.adobe.com/labs/textlayout/flash/display/BitmapData.html#compare()

Thursday, July 23, 2009

July 23rd

import flash.display.Bitmap; 
import flash.display.BitmapData; 

var video:Video = new Video();
addChild(video);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("640x480.flv");
 
video.attachNetStream(ns);
 
function ns_onMetaData(item:Object):void {
    trace("metaData");
    // Resize video instance.
    video.width = item.width;
    video.height = item.height;
    // Center video instance on Stage.
    video.x = (stage.stageWidth - video.width) / 2;
    video.y = (stage.stageHeight - video.height) / 2;
}


function ns_onCuePoint(item:Object):void {
    trace("cuePoint");
    trace(item.name + "\t" + item.time);
}
//var snapshot : BitmapData; 

//snapshot = new BitmapData(myVideo.width,myVideo.height);  

//function takeSnapshot()  
//{  
  // snapshot.draw(myVideo);  
//}  
  
//call takeSnapshot every 100ms (0.1s)  
 
  
var now : BitmapData; 
var before: BitmapData;  
 
now = new BitmapData(video.width,video.height);  

//setInterval(this,"takeSnapshot",100);
//setInterval(this,"takeSnapshot",100); 

function takeSnapshot()  
{  
   now.draw(video);  
   // 1. capture 'now' 2. Do something 3. copy now to before   
   before=now.clone();  
 
//var histogram(hRect:Rectangle=null):Vector.> = BitmapData.histogram;  
var oldC = before.histogram();
var newC = now.histogram();
if (oldC != newC) {  
   trace('Activity... in region');  
}
}

function updateHistograms((bmpData:BitmapData, sprites:Vector.):void {

// histogram is a Vector in two dimensions
// notice the interesting type Vector.>
var hst:Vector.> = bmpData.histogram();

var height:int=128; // height for diagrams
var maxValue:Number;
var value:Number;
var i:int;
var clr:int = 16; // value for bitwise shift left, start with red
// channel = 0:red, 1:green, 2:blue

for (var channel:int = 0; channel!=3; channel++) {

// find the max value on the histogram,
// i goes from 1 to 254,
// I discarded the 0 and 0xFF values to get a better balanced chart

maxValue =0.0;
for (i=1; i!=255; i++) {
value = hst[channel][i];
maxValue = value>maxValue ? value : maxValue;
}

with (sprites[channel].graphics) {
// empty and white background
clear();
beginFill(0xFFFFFF,1.0);
drawRect(0,0,255,height);
// draw a vertical line for each value with a corresponding color

i=0;
for each(value in hst[channel]) {
lineStyle(1.0,i<
moveTo(i,height);
lineTo(i++,Math.max(0.0,height-value*height/maxValue) );
}

}
clr -= 8;
}
}


//function histogram(hRect:Rectangle = null):Vector



}

Today, I shall also compress video to a more suitable size.

Monday, July 20, 2009

July 20th

Have started experimenting with the Histogram class for comparing bitmaps.

Using http://www.as3apex.com/uncategorized/flash-10s-bitmapdatahistogram-is-really-slow/and http://books.google.com/books?id=xm9COWxqfIkC&pg=PT233&dq=histogram+flash+actionscript&client=safari for guidence.

Today's code

import flash.display.Bitmap; 
import flash.display.BitmapData; 

var video:Video = new Video();
addChild(video);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("640x480.flv");
 
video.attachNetStream(ns);
 
function ns_onMetaData(item:Object):void {
    trace("metaData");
    // Resize video instance.
    video.width = item.width;
    video.height = item.height;
    // Center video instance on Stage.
    video.x = (stage.stageWidth - video.width) / 2;
    video.y = (stage.stageHeight - video.height) / 2;
}


function ns_onCuePoint(item:Object):void {
    trace("cuePoint");
    trace(item.name + "\t" + item.time);
}
//var snapshot : BitmapData; 

//snapshot = new BitmapData(myVideo.width,myVideo.height);  

//function takeSnapshot()  
//{  
  // snapshot.draw(myVideo);  
//}  
  
//call takeSnapshot every 100ms (0.1s)  
 
  
var now : BitmapData; 
var before: BitmapData;  
 
now = new BitmapData(video.width,video.height);  

//setInterval(this,"takeSnapshot",100);
//setInterval(this,"takeSnapshot",100); 

function takeSnapshot()  
{  
   now.draw(video);  
   // 1. capture 'now' 2. Do something 3. copy now to before   
   before=now.clone();  
 
var histogram(hRect:Rectangle=null):Vector.> = BitmapData.histogram;  
var oldC = before.histogram();
var newC = now.histogram();
if (oldC != newC) {  
   trace('Activity... in region');  
}
}



//function histogram(hRect:Rectangle = null):Vector


Friday, July 17, 2009

July 17th

Added Code from http://actionscriptexamples.com/2008/02/26/loading-flv-files-in-actionscript-30-using-the-netconnection-and-netstream-classes/ as a new loader in order to facilate video access.

var video:Video = new Video();
addChild(video);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("640x480.flv");
 
video.attachNetStream(ns);
 
function ns_onMetaData(item:Object):void {
    trace("metaData");
    // Resize video instance.
    video.width = item.width;
    video.height = item.height;
    // Center video instance on Stage.
    video.x = (stage.stageWidth - video.width) / 2;
    video.y = (stage.stageHeight - video.height) / 2;
}

//var snapshot : BitmapData; 

//snapshot = new BitmapData(myVideo.width,myVideo.height);  

//function takeSnapshot()  
//{  
  // snapshot.draw(myVideo);  
//}  
  
//call takeSnapshot every 100ms (0.1s)  
//setInterval(this,"takeSnapshot",100);  
  
var now : BitmapData; 
var before: BitmapData;  
 
now = new BitmapData(video.width,video.height);  
 
function takeSnapshot()  
{  
   now.draw(video);  
// 1. capture 'now' 2. Do something 3. copy now to before   
   before=now.clone();  
}  

var oldC = computeAverageColour(before,10,10,20,20);  
var newC = computeAverageColour(now,10,10,20,20);  
if (oldC != newC) {  
   trace('Activity... in region');  
  
function computeAverageColour(bm:BitmapData, x:int, y:int, w:int, h:int):Number{  
   var totalR:Number = 0; // 32-bit colour is formatted  
   var totalG:Number = 0; // 8 bits 8 bits 8 bits 8 bits  
   var totalB:Number = 0; //    A      R      G       B  
   var count:Number = 0;  
 
   for (var j:Number = y; j < (y + h); j++) {  
     for (var i:Number = x;  i < (x + w); i++) {  
        var col:Number = bm.getPixel(i, j);  
        var red:Number = (col & 0xFF0000) >> 16;  
        var green:Number = (col & 0x00FF00) >> 8;  
        var blue:Number = col & 0x0000FF;  
        totalR += red;  
        totalG += green;  
        totalB += blue;  
        count++;  
     }  
  }  
// Calculate the average of each colour channel  
  var tR:Number = Math.round(totalR/count);  
  var tG:Number = Math.round(totalG/count);  
  var tB:Number = Math.round(totalB/count);  
// Join them together  
  var targetCol:Number = tR <<>
  return  targetCol;  
}   

Wednesday, July 15, 2009

July 15th

Currently code
import fl.video.*;

import flash.display.BitmapData; 
 
var myVideo:Video;  
//var myCamera:Camera = Camera.get();  
  
//myVideo.attachVideo("640x480.flv");  
 
var snapshot : BitmapData; 
 
snapshot = new BitmapData(myVideo.width,myVideo.height);  
  
//function takeSnapshot()  
//{  
//   snapshot.draw(myVideo);  
//}  
  
// call takeSnapshot every 100ms (0.1s)  
//setInterval(this,"takeSnapshot",100);  
  
var now : BitmapData; 
var before: BitmapData;  
 
now = new BitmapData(myVideo.width,myVideo.height);  
 
function takeSnapshot2()  
{  
   now.draw(myVideo);  
// 1. capture 'now' 2. Do something 3. copy now to before   
   before=now.clone();  
}  

oldC = computeAverageColour(before,10,10,20,20);  
newC = computeAverageColour(now,10,10,20,20);  
if (oldC != newC) {  
   trace('Activity... in region');  
  
function computeAverageColour(bm:BitmapData, x:int, y:int, w:int, h:int):Number{  
   var totalR:Number = 0; // 32-bit colour is formatted  
   var totalG:Number = 0; // 8 bits 8 bits 8 bits 8 bits  
   var totalB:Number = 0; //    A      R      G       B  
   var count:Number = 0;  
 
   for (var j:Number = y; j < (y + h); j++) {  
     for (var i:Number = x;  i < (x + w); i++) {  
        var col:Number = bm.getPixel(i, j);  
        var red:Number = (col & 0xFF0000) >> 16;  
        var green:Number = (col & 0x00FF00) >> 8;  
        var blue:Number = col & 0x0000FF;  
        totalR += red;  
        totalG += green;  
        totalB += blue;  
        count++;  
     }  
  }  
// Calculate the average of each colour channel  
  var tR:Number = Math.round(totalR/count);  
  var tG:Number = Math.round(totalG/count);  
  var tB:Number = Math.round(totalB/count);  
// Join them together  
  var targetCol:Number = tR <<>
  return  targetCol;  
}   

Experience issues with oldC and newC. Today I'll strive to resolve them.

Thursday, July 2, 2009

2nd July

Working out taking colour average difference. using combination of code used in Practical 10  of CS6114 Digital Video Compression and Delivery and the example found on this website. http://theolagendijk.wordpress.com/2006/07/01/taking-color-average-from-image/ specifically this part.

import flash.display.BitmapData;

var image:MovieClip = this["image"];
image._x = 100;
image._y = 100;
image._visible = true;

var bitmap:BitmapData = new BitmapData(image._width,image._height,false);
bitmap.draw(image);

var sumColorR:Number = 0;
var sumColorG:Number = 0;
var sumColorB:Number = 0;
var count:Number = 0;

for(var h:Number = 0; h < number =" 0;" number =" bitmap.getPixel(w,">>> 16;
sumColorG += (col & 0×00FF00) >>> 8;
sumColorB += (col & 0×0000FF);
count++;
}
}

It is hoped that once I have this working, I will be be able to attach filters and use more suitable methods of difference detection.

Have also begun preliminary interface design

Thursday, June 4, 2009

Day 1

Tasks performed today:
An Evaluation of Video Cut Detection Techniques - reread
Video Shot Cut Detection Using Adaptive Thresholding - reread

Tasks to be performed:
Reread remaining essays.
Write Project plan.