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/mpisearch/main.cc File Reference

#include "mpisearchFaceDetector.h"
#include <list>
#include <algorithm>
#include <Magick++.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <argp.h>

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

Include dependency graph

Go to the source code of this file.

Classes

struct  arguments

Defines

#define BINARY
#define FALSE   0
#define MAX_NUM_IMAGES   10
#define TRUE   1

Functions

double difftv (const struct timeval &t1, const struct timeval &t0)
int main (int argc, char **argv)
error_t parse_opt (int key, char *arg, struct argp_state *state)

Variables

argp argp = {options, parse_opt, args_doc, doc}
const char * argp_program_bug_address = "ianfasel@cogsci.ucsd.edu"
const char * argp_program_version = "2.0"
char args_doc [] = "image1 image2 ... imageN (N <= 10)"
char doc []
argp_option options []


Define Documentation

#define BINARY
 

Definition at line 43 of file Apps/unix/mpisearch/main.cc.

#define FALSE   0
 

Definition at line 39 of file Apps/unix/mpisearch/main.cc.

#define MAX_NUM_IMAGES   10
 

Definition at line 41 of file Apps/unix/mpisearch/main.cc.

#define TRUE   1
 

Definition at line 40 of file Apps/unix/mpisearch/main.cc.


Function Documentation

double difftv const struct timeval &  t1,
const struct timeval &  t0
[inline, static]
 

Definition at line 98 of file Apps/unix/mpisearch/main.cc.

00099 { return( (t1.tv_sec -t0.tv_sec )*1.0 +(t1.tv_usec-t0.tv_usec)*1e-6); }

int main int  argc,
char **  argv
 

Definition at line 103 of file Apps/unix/mpisearch/main.cc.

References MPISearchObjectDetector::AdjSearchWindow(), argp, arguments::args, arguments::cfile, ObjectList::clear(), difftv(), arguments::emofile, arguments::emoFlag, ObjectList::empty(), FaceBoxList, faces, ObjectList::front(), i, image, arguments::matfile, ObjectList::objects, ObjectList::pop_front(), MPISearchObjectDetector::resetStream(), MPISearchObjectDetector::search(), ObjectList::simplify(), TSquare::size, ObjectList::size(), ObjectList::sort(), Square, TSquare::x, and TSquare::y.

00104 {  
00105   struct arguments arguments;
00106   // default values
00107   strcpy(arguments.matfile,"out.mat");
00108   strcpy(arguments.cfile,"ci.xml");
00109   strcpy(arguments.emofile,"emo.xml");
00110   arguments.emoFlag = 0;
00111   for(int i = 0; i<MAX_NUM_IMAGES; i++)
00112     arguments.args[i] = 0;
00113     
00114   // get values from command line
00115 #ifndef __APPLE_CC__
00116   argp_parse(&argp, argc, argv, 0, 0, &arguments);
00117 #else
00118   int opt_count = 0;
00119   arguments.args[0] = (char *)malloc(256 * sizeof(char));
00120   if(argc==2)
00121     strcpy(arguments.args[0],argv[1]);
00122   else{
00123     arguments.emoFlag = 1;
00124     strcpy(arguments.args[0],argv[2]);
00125   }
00126   
00127 #endif
00128 
00129   //
00130   // Initialize the MPISearchObjectDetector object
00131   //
00132   MPISearchFaceDetector mpi;
00133 
00134   // 
00135   // Loop through all images
00136   //
00137   int last_width = 0, last_height = 0;
00138   int arg_count = -1;
00139   while(arguments.args[++arg_count]!=0){
00140     // Try and open the file.  
00141     cout << "opening file " <<  arguments.args[arg_count] << endl; 
00142     try { 
00143       Image image( arguments.args[arg_count] );
00144 
00145       // 
00146       // allocate our buffer and write the pixels to it. 
00147       //
00148       RImage<float> pixels(image.columns(), image.rows());
00149 
00150       image.quantizeColors ( 256 ); // convert to 256 colors
00151       image.quantize( ); // convert to grayscale
00152 
00153       image.write(0,0, image.columns(), image.rows(), "I", FloatPixel, pixels.array);
00154       image.display();
00155 
00156       //pixels.print(); // why are colors between 0 and 100 ?
00157 
00158       cout << "Image: " << arguments.args[arg_count]
00159            << " - " << pixels.width 
00160            << "x" << pixels.height 
00161            << endl;
00162       if((pixels.width != last_width) || (pixels.height != last_height))
00163             mpi.resetStream(pixels.width, pixels.height, 0.75);
00164       last_width = pixels.width ; last_height = pixels.height;
00165 
00166       FaceBoxList faces;
00167 
00168       struct timeval tv_now, last, tv_first, final;
00169 
00170       int numwindows, nframes = 50, num_successes = 0;
00171       Square trackedFace;
00172       // Search nframes times
00173       for(int fc = 0; fc < nframes; ++fc){
00174         faces.clear();
00175         gettimeofday(&last,0);
00176         if(fc==0)
00177           numwindows = mpi.search(pixels, faces, 0, 1.25);
00178         else
00179           numwindows = mpi.search(pixels, faces, 1, .75);
00180         gettimeofday(&tv_now,0);
00181         if(fc == 0){
00182           cout << "numwindows: " << numwindows << endl;
00183           printf("\tThe first search took %g seconds. \n", difftv(tv_now, last));
00184           printf("Initially found %d faces in %s.\n", faces.size(), arguments.args[arg_count]);
00185         }
00186         faces.simplify( 0.2 ); //0.24);
00187         if(fc == 0)
00188           printf("Now found %d.\n", faces.size());
00189         if(!faces.empty()){
00190           faces.objects.sort(decreasing<int>);
00191           trackedFace = faces.front();
00192           //cout << "Front face size: "<< trackedFace.size << endl;
00193           num_successes++;
00194         }
00195         mpi.AdjSearchWindow(trackedFace);
00196         if(fc == 0)
00197           gettimeofday(&tv_first,0);
00198       }
00199       gettimeofday(&final,0);
00200       printf("\tTheoretical frame rate for one-face tracking: %g fps. \n", (nframes-1) / difftv(final, tv_first));
00201       printf("\tFound face in %2.0f%% of frames\n",((float)num_successes/(float)nframes) * 100.0);       
00202 
00203       if(faces.size() != 0) {
00204         image.strokeColor("white");
00205         image.strokeWidth(1);
00206         image.fillColor("none" );
00207 
00208         while(!faces.empty( ))
00209         {
00210           Square face = faces.front();  
00211           faces.pop_front();
00212 
00213           image.draw( DrawableRectangle(face.x, face.y, 
00214                 face.x + face.size, face.y + face.size));
00215 
00216           //cout << "square_size: " << face->size << " x: " << face->x << " y: " << face->y << endl;
00217 
00218           //delete face;
00219         }
00220         
00221         image.display();
00222         //image.write("result.jpg");
00223       }
00224     }
00225     catch ( ErrorFileOpen &error ) {
00226       cerr << "Error opening file: " 
00227            <<  arguments.args[arg_count]
00228            << ". ImageMagick said: " 
00229            << error.what() 
00230            << endl;
00231     }
00232   } 
00233   return 0;
00234 }

Here is the call graph for this function:

error_t parse_opt int  key,
char *  arg,
struct argp_state *  state
[static]
 

Definition at line 67 of file Apps/unix/mpisearch/main.cc.

References arguments::args, and state.

00067                                                                        {
00068   // Get input argument from argp_parse, which is our
00069   // arguments pointer.
00070   struct arguments *arguments = static_cast<struct arguments *>(state->input);
00071   
00072   switch(key)
00073     {
00074     case ARGP_KEY_ARG:
00075       if(state->arg_num >= 10)   // too many arguments
00076         argp_usage (state);
00077       arguments->args[state->arg_num] = arg;
00078       break;
00079     case ARGP_KEY_NO_ARGS:
00080       argp_usage(state);
00081       break;
00082     case ARGP_KEY_END:
00083       if (state->arg_num <= 0) // not enough arguments
00084         argp_usage(state);
00085       break;
00086 
00087     default:
00088       return ARGP_ERR_UNKNOWN;
00089     }
00090   return 0;
00091 }


Variable Documentation

struct argp argp = {options, parse_opt, args_doc, doc} [static]
 

Definition at line 94 of file Apps/unix/mpisearch/main.cc.

Referenced by main().

const char* argp_program_bug_address = "ianfasel@cogsci.ucsd.edu"
 

Definition at line 50 of file Apps/unix/mpisearch/main.cc.

const char* argp_program_version = "2.0"
 

Definition at line 49 of file Apps/unix/mpisearch/main.cc.

char args_doc[] = "image1 image2 ... imageN (N <= 10)" [static]
 

Definition at line 93 of file Apps/unix/mpisearch/main.cc.

char doc[] [static]
 

Initial value:

 "An example program demonstrating the use of libmpisearch."
"To run the face detector on an image file, accepting all defaults, "
"type:\n\t mpisearch <image>\nwhere <image> is the name of the image file. "
"You can also specify the following options:\vEnjoy!"

Definition at line 51 of file Apps/unix/mpisearch/main.cc.

struct argp_option options[] [static]
 

Initial value:

 {
  {0}
}

Definition at line 56 of file Apps/unix/mpisearch/main.cc.


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