Archive for math

Face / Mimik tracking in AS3


Once again Tomek alias Og2t wrote a great flash demo. This time its about machine vision and just awesome. It’s motion based head / eyetracking with a lot of cool “hacks” like blob detection – histogram analysis – motion detection and more. Furthermore Tomek wants to provide a full framework.

This is a part of the whole video filter framework I am developing just now, the inspiration came from Joa Ebert’s Image Processing library (as far as I know, he’s cooking a complete rewrite). The full source code (including Pixel Bender kernels and examples) will be soon released on Google Code and will feature face/eye tracking/gestures and few other things (surprise!) A lot of people are very sceptic about the whole eye tracking idea, they don’t believe it’s precise enough to make any use of it – I will prove that it is, and it works! (just watch closely how it tracks my eyeballs on the video!)

I tried it, but I still prefer the camshift algorithm for face detection. Anyway: GREAT WORK!

Must see -> Erik Natzke

As far as i got it Erik Natzke creates art using tech (Flash for sure, maybe processing too). You can also buy his prints.  Here are some images. :






SURF the next big thing

SURF is a computer vision technique which helps doing crazy things ;) Here is some footage showing whats possible. NOTE: no flash implementation yet ;) – I think it wouldn’t work -> performance

openFrameworks & OpenCV SURF from postspectacular on Vimeo.

Augmenting a Postcard from Julian Oliver on Vimeo.

Optimized edge detection algorithm.

I optimized the edge detection (sobel) algorithm found here a little. Still there is a lot potential for optimizing things. You can find tipps in joa’s wiki

Here is my code

private function detectEdges(bmd : BitmapData) : void
 var myGausianFilter : ConvolutionFilter =
 new ConvolutionFilter(5, 5, 
 // Edge Data
 function findEdges() : void
  //Apply Smoothing Filter
  bmd.applyFilter(bmd, bmd.rect, new Point(0, 0), myGausianFilter);
  //Create New Bitmap to hold edge data
  ourEdgeData = new BitmapData(bmd.width, bmd.height, false);
  var gx : int;;
  var gy : int;
  var gray : uint;
  //Loop through original data and calculate edges
  for(var w : int = 0;w < bmd.width; w++)
   for(var h : int = 0;h < bmd.height; h++)
    pV0 = int(bmd.getPixel(w, h - 1)/ uint(0xffffff)*255);
    pV45 = int(bmd.getPixel(w + 1, h - 1)/ uint(0xffffff)*255);
    pV90 = int(bmd.getPixel(w + 1, h)/ uint(0xffffff)*255);
    pV35 = int(bmd.getPixel(w + 1, h + 1)/ uint(0xffffff)*255);
    pV80 = int(bmd.getPixel(w, h + 1)/ uint(0xffffff)*255);
    pV225 = int(bmd.getPixel(w - 1, h + 1)/ uint(0xffffff)*255);
    pV270 = int(bmd.getPixel(w - 1, h)/ uint(0xffffff)*255);			
    pV315 = int(bmd.getPixel(w - 1, h - 1)/ uint(0xffffff)*255);	 
    gx = (pV45+(pV90*2)+pV35)-(pV315+(pV270*2)+pV225);
    gy = (pV315+(pV0*2)+pV45)-(pV225+(pV80*2)+pV35);
    gray = Math.abs(gx) + Math.abs(gy);
    // Check to see if values aren't our of bounds
    if(gray > 255)
     gray = 255;
    if(gray < 0)
	  gray = 0;
    // Build New Pixel
    newPixelValue = (gray << 16)+(gray << 8)+(gray);
    // Copy New Pixel Into Edge Data Bitmap
    ourEdgeData.setPixel(w, h, newPixelValue);	
 function getGray(pixelValue : uint) : uint
  var red : uint = (pixelValue >> 16 & 0xFF) * 0.30;
  var green : uint = (pixelValue >> 8 & 0xFF) * 0.59;
  var blue : uint = (pixelValue & 0xFF) * 0.11;
  return (red + green + blue);
 _bmp3.bitmapData = ourEdgeData;

Edge detection in Flash

here is a good post about edge detection with the sobel-operator


Works really well, but does not fit my needs.

Face tracking!

I found

The Camshift algorithm is propably the best tracking algorithm for the flash platform. It’s stable, fast and good coded. Love it!

Flashtip : Zoom in a clip to a specific point

Imagine you have to zoom in a mc on a specific point.
This math snippet works fine for me (I used TweenLite in my Code):

var tmpEndX : Number = ((spr.width)-(width*scaleFact))/2;
var tmpEndY : Number = ((spr.height)-(spr.height*scaleFact))/2;
var tmpXShift : Number = (mouseX-(width/2))*scaleFact;
var tmpYShift : Number = (mouseY-(spr.height/2))*scaleFact;, 0.5,{scaleX : scaleFact});, 0.5,{scaleY : scaleFact});, 0.5,{x : tmpEndX - tmpXShift});, 0.5,{y : tmpEndY - tmpYShift});

Demo and full Class here

vertex detection in quad


You have a quad outline as point data, and want to detect the four vertices

I googled that problem a lot but couldn’t find any solution that fitted my needs. Moreover I didn’t want to copy paste something I do not really understand, so I solved it my way

Read more »