Tuesday, November 4, 2008

AllSeeing: an idea...

Knowing that in our senior year of college we would be required to complete extensive research on a topic of our choice was enough to inspire late night brain storming sessions among my colleagues in the Computer Science department. Most of these sessions resulted in us throwing outrageous ideas on the table and talking them to death.

Out of these sessions came the following idea. Would it not be cool to teach a computer to see? More specifically, get a web cam to follow people and look them in the face? This has been done before. There are commercial products that can keep a face centered. Still, it would be pretty cool to get a system like this up and running with nothing more than a web cam, some servo motors, and a parallel port.

It is my opinion that most AI of today is a bunch of smoke an mirrors. This is not bad. Smoke and mirrors can do some pretty impressive things. The reason this idea was never implemented by my colleagues is because from a Computer Science perspective it had already been done. If you have a subscription to the ACM Library you can read about detailed algorithms for Skin Detection, Face Detection, and Face Recognition. Surprisingly, Skin Detection can be implemented with only a few lines of C. Observe my go at this:


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <Magick++.h>
using namespace Magick;

int main(int argc, char **argv) {
    Image image;
    image.read(argv[1]);
   
    Color white = Color(MaxRGB, MaxRGB, MaxRGB, 0);
    Color black = Color(0, 0, 0, 0);
   
    int width = image.columns();
    int height = image.rows();
    printf("Width: %d Height: %d \n\n", width, height);

    int x = 0;
    int y = 0;
    for(x=0;x<width;x++){
        for(y=0;y<height;y++){
            ColorRGB pixel = image.pixelColor(x,y);
            double red = pixel.red();
            double green = pixel.green();
            double blue = pixel.blue();
           
            double a = (red+green+blue)/red;
            double b = (red+green+blue)/blue;
            if(a<2.5 && a>2 && b<4 && b>3){
                //image.pixelColor(x,y, white);
            }
            else{
                image.pixelColor(x,y,black);
            }
        }
    }
    image.write(argv[2]);
    return 0;
}


I executed this very crude and very fast solution on Angela Lansbury and Micheal Jordan, choosing these two people partially by random and also in order to show the versatility of the solution. Below is the result.






As you can see, the result looks very promising. So... skin detection is a check. All that would be left as far as algorithms would be the face detector, which I feel would also be trivial. This is where Computer Science ends and Electrical Engineering begins. In order to have a complete system the web cam would have to be mounted on a platform that would allow it to follow a face. This platform would have to be controlled from the same executing C code that is analyzing the web cam feed. Sounds like I need to dig into my basic electronics books, something I haven't done since junior year of high school.

No comments:

Post a Comment