Issues with capturing motion weight in Flash/as3
Fairly new coder here so apologies if there are glaring mistakes in my logic. I am having trouble getting the difference value of current and previous bitmapData frames in this motion detection script. I am using Soulwire's (blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking) code for the motion detection but am having problems implementing a little bit of code that I think should work for grabbing motion weight. The object is to read and differentiate between left and right swipes of the hand- movement from one side to the other yields a negative to positive or positive to negative number. Here's the track() function and the var _weight is what I'm looking for:
public function track() : void
{
_now.draw(_src, _mtx);
_now.draw(_old, null, null, BlendMode.DIFFERENCE);
_now.applyFilter(_now, _now.rect, new Point(), _col);
_now.applyFilter(_now, _now.rect, new Point(), _blr);
_now.threshold(_now, _now.rect, new Point(), '>', 0xFF333333, 0xFFFFFFFF);
_old.draw(_src, _mtx);
//simple weight gathering though prob need some time smoothing
var totalPix:int = _old.width * _old.height;
var index:int=totalPix+1;
var useIndex: int;
var xPix:int;
var yPix:int;
while (--index > 0){
useIndex = index-1;
xPix = useIndex % _old.width;
yPix = int(useIndex/_old.width);
if (Math.abs((_old.getPixel(xPix, yPix)>>16)-(_now.getPixel(xPix, yPix)>>16)) >30){
_weight += (((index/4) % _old.width) == 0 ? ((index-1)/4 % _old.width):((index/4) %_old.width)-(_old.width/2));
}
index -= 4;
}
For some reason it's giving me a 0 value for (_now.getPixel(xPix,yPix)>>16). I am wondering if this is because _old is drawn over _now? Thanks for any help.
