The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Apps/unix/eyefinder/main.cc File Reference

#include "eyefinderBinary.h"
#include "faceobject.h"
#include <list>
#include <Magick++.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>

Include dependency graph for Apps/unix/eyefinder/main.cc:

Include dependency graph

Go to the source code of this file.

Classes

struct  arguments

Defines

#define FALSE   0
#define MAX_NUM_IMAGES   20
#define TRUE   1

Functions

double difftv (timeval t1, timeval t0)
int main (int argc, char **argv)


Define Documentation

#define FALSE   0
 

Definition at line 33 of file Apps/unix/eyefinder/main.cc.

#define MAX_NUM_IMAGES   20
 

Definition at line 47 of file Apps/unix/eyefinder/main.cc.

#define TRUE   1
 

Definition at line 34 of file Apps/unix/eyefinder/main.cc.


Function Documentation

double difftv timeval  t1,
timeval  t0
 

Definition at line 36 of file Apps/unix/eyefinder/main.cc.

References s.

00036                                       {
00037         double s;
00038         double secs = t1.tv_sec - t0.tv_sec;
00039         double usecs = ((double)t1.tv_usec) - ((double)t0.tv_usec);
00040         usecs *= 1e-6;
00041         s = secs+usecs;
00042         return s;
00043 }

int main int  argc,
char **  argv
 

Definition at line 52 of file Apps/unix/eyefinder/main.cc.

References arguments::args, ObjectList::begin(), difftv(), ObjectList::end(), FaceObject::eyes, faces, i, im, image, max, ObjectList::size(), sprintf(), wt_avg, VisualObject::x, bEyesObject::xLeft, bEyesObject::xRight, VisualObject::xSize, VisualObject::y, bEyesObject::yLeft, bEyesObject::yRight, and VisualObject::ySize.

00053 {  
00054         int i;
00055   struct arguments arguments;
00056   for(i = 0; i<MAX_NUM_IMAGES; i++)
00057     arguments.args[i] = 0;
00058     
00059   // get values from command line
00060   if(argc==2) {
00061         arguments.args[0] = (char *)malloc(256 * sizeof(char));
00062     strcpy(arguments.args[0],argv[1]);
00063         }
00064   else{
00065                 for (i = 0; i < argc-1 && i < MAX_NUM_IMAGES; i++) {
00066                         arguments.args[i] = (char *)malloc(256 * sizeof(char));
00067         strcpy(arguments.args[i],argv[i+1]);
00068                 }
00069   }
00070 
00071 
00072   struct timeval tv_now, last;
00073   MPEyeFinder *eyefinder;
00074   eyefinder = new MPEyeFinderBinary();
00075 
00076         int im = 0;
00077         while (arguments.args[im] && im < MAX_NUM_IMAGES) {
00078     // Try and open the file.  
00079     try { 
00080       Image image( arguments.args[im] );
00081 
00082       // 
00083       // allocate our buffer and write the pixels to it. 
00084       //
00085       RImage<float> pixels(image.columns(), image.rows());
00086                 eyefinder->initStream(pixels.width, pixels.height);
00087 
00088       image.quantizeColors ( 256 ); // convert to 256 colors
00089       image.quantize( ); // convert to grayscale
00090 
00091       image.write(0,0, image.columns(), image.rows(), "I", FloatPixel, pixels.array);
00092       //image.display();
00093 
00094       cout << "Image: " << arguments.args[im]
00095            << " - " << pixels.width 
00096            << "x" << pixels.height 
00097            << endl;
00098 
00099       VisualObject faces;
00100 
00101       // start the clock
00102       struct timeval tv_now, last;
00103       double numwindows;
00104       // Search nframes times, using ROI
00105       gettimeofday(&last,0);
00106       numwindows = eyefinder->findEyes(pixels, faces, 1.25, wt_avg);
00107       gettimeofday(&tv_now,0);
00108       printf("search took %g seconds. \n", difftv(tv_now, last));
00109       cout << "numwindows: " << numwindows << endl;
00110       
00111 
00112       if(faces.size() != 0) {
00113         image.strokeWidth(1);
00114         image.fillColor("none" );
00115                                 
00116         list<VisualObject *>::iterator face = faces.begin();
00117         int facenumber=0;
00118         for( ; face != faces.end(); ++face) {
00119           image.strokeColor("white");
00120           FaceObject *fo = static_cast<FaceObject*>(*face);
00121           image.draw( DrawableRectangle( fo->x, fo->y, fo->x+fo->xSize, fo->y+fo->ySize));
00122           image.strokeColor("red");
00123           int eyeSize = static_cast<int>(fo->xSize * 0.1);
00124           //lefteye
00125           image.draw( DrawableRectangle( max(fo->eyes.xLeft-eyeSize, 0),  max(fo->eyes.yLeft-eyeSize,0),
00126                                          min(fo->eyes.xLeft+eyeSize, pixels.width), min(fo->eyes.yLeft+eyeSize, pixels.height)));
00127           //righteye
00128           image.draw( DrawableRectangle( max(fo->eyes.xRight-eyeSize, 0),  max(fo->eyes.yRight-eyeSize,0),min(fo->eyes.xRight+eyeSize, pixels.width), min(fo->eyes.yRight+eyeSize, pixels.height)));
00129           
00130           Image tmpimage = image;
00131           tmpimage.crop(Geometry((int) fo->xSize, (int) fo->ySize , (int) fo->x, (int) fo->y));
00132           tmpimage.scale(Geometry(200,200,0,0));
00133           char outfilename[20];
00134           printf("Processing Face %d\n",facenumber);
00135           sprintf(outfilename,"face%d.jpg",++facenumber);
00136           tmpimage.write(outfilename); 
00137           
00138         }
00139         image.display();
00140       }
00141     }
00142     catch ( ErrorFileOpen &error ) {
00143       cerr << "Error opening file: " 
00144            <<  arguments.args[im]
00145            << ". ImageMagick said: " 
00146            << error.what() 
00147            << endl;
00148     }
00149                 im++;
00150   } 
00151   return 0;
00152 }

Here is the call graph for this function:


Generated on Mon Nov 8 17:08:10 2004 for MPT by  doxygen 1.3.9.1