Text Recognition

Wednesday, January 21, 2009

I recently decided to try to make a text recognition application in Flash AS3. I thought through most of the logic in the car one day and found that it was not nearly as difficult as I had thought.
As it turns out, I was able to get a pretty nice prototype in only 150 lines of code!
Click the image to try it out!

The Concept

When the user clicks the mouse down, tracks the mouse movement to an array. When the user releases the mouse, stop the recorder and match it's array values to a unique identity, a letter of the Alphabet.


Psuedocode

//global vars
var startX:Number = 0;
var startY:Number = 0;
var coordsArray:Array = new Array();

//add event listeners
addEventListener(MouseEvent.MOUSE_DOWN, start_record);
addEventListener(MouseEvent.MOUSE_UP, convert_record);

function start_record(e:MouseEvent):void{
startX = mouseX;
startY = mouseY;
addEventListener(Event.ENTER_FRAME, record);
}

function record(e:Event):void{
if(mouseX > startX){
//I moved the mouse Right
coordsArray.push("R");
}
else if(mouseX < style="color: rgb(153, 153, 153);">
//I moved the mouse Left
coordsArray.push("L");
}
}

function convert_record(e:MouseEvent):void{
removeEventListener(Event.ENTER_FRAME, record);

//now convert array values to Alphabet letter
switch(coordsArray.toString()){
case "U,R,D":
//the letter is A
break;
case "D,U,R,D,L":
//the letter is B
break;
case "L,D,R":
//the letter is C
break;
}
}


There were a few tweaks I had to make to enhance the performance, but you get the idea. It works pretty well! Success!

0 comments:

Post a Comment