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

Libraries/blinkDetector/src/main.cc File Reference

#include "blink.h"
#include <list>
#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 Libraries/blinkDetector/src/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 42 of file Libraries/blinkDetector/src/main.cc.

#define FALSE   0
 

Definition at line 38 of file Libraries/blinkDetector/src/main.cc.

#define MAX_NUM_IMAGES   10
 

Definition at line 40 of file Libraries/blinkDetector/src/main.cc.

#define TRUE   1
 

Definition at line 39 of file Libraries/blinkDetector/src/main.cc.


Function Documentation

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

Definition at line 132 of file Libraries/blinkDetector/src/main.cc.

00133 { 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 137 of file Libraries/blinkDetector/src/main.cc.

References argp, arguments::args, arguments::cfile, ObjectList::clear(), difftv(), arguments::emofile, arguments::emoFlag, ObjectList::empty(), FaceBoxList, faces, MPBlink::findBlinks(), ObjectList::front(), i, image, arguments::matfile, ObjectList::pop_front(), ObjectList::simplify(), TSquare::size, ObjectList::size(), Square, TSquare::x, and TSquare::y.

00138 {  
00139   struct arguments arguments;
00140   // default values
00141   strcpy(arguments.matfile,"out.mat");
00142   strcpy(arguments.cfile,"ci.xml");
00143   strcpy(arguments.emofile,"emo.xml");
00144   arguments.emoFlag = 0;
00145   for(int i = 0; i<MAX_NUM_IMAGES; i++)
00146     arguments.args[i] = 0;
00147     
00148   // get values from command line
00149 #ifndef __APPLE_CC__
00150   argp_parse(&argp, argc, argv, 0, 0, &arguments);
00151 #else
00152   int opt_count = 0;
00153   arguments.args[0] = (char *)malloc(256 * sizeof(char));
00154   if(argc==2)
00155     strcpy(arguments.args[0],argv[1]);
00156   else{
00157     arguments.emoFlag = 1;
00158     strcpy(arguments.args[0],argv[2]);
00159   }
00160   if(IsAltiVecAvailable())
00161     cout << "AltiVec detected" << endl;
00162   else
00163     cout << "No AltiVec on this Mac" << endl;
00164   
00165 #endif
00166 
00167   //
00168   // Initialize the MPBlink object
00169   //
00170 
00171   MPBlink blink;
00172 
00173   // 
00174   // Loop through all images
00175   //
00176   int arg_count = -1;
00177   while(arguments.args[++arg_count]!=0){
00178     // Try and open the file.  
00179     try { 
00180       Image image( arguments.args[arg_count] );
00181 
00182       // 
00183       // allocate our buffer and write the pixels to it. 
00184       //
00185       RImage<float> pixels(image.columns(), image.rows());
00186 
00187       image.quantizeColors ( 256 ); // convert to 256 colors
00188       image.quantize( ); // convert to grayscale
00189 
00190       image.write(0,0, image.columns(), image.rows(), "I", FloatPixel, pixels.array);
00191       //image.display();
00192 
00193       cout << "Image: " << arguments.args[arg_count]
00194            << " - " << pixels.width 
00195            << "x" << pixels.height 
00196            << endl;
00197 
00198       FaceBoxList faces;
00199 
00200       // start the clock
00201       struct timeval tv_now, last, tv_first, final;
00202       gettimeofday(&last,0);
00203       int nframes = 31;
00204       double blinkness;
00205       // Search nframes times, using ROI
00206       for(int fc = 0; fc < nframes; ++fc){
00207         faces.clear();
00208         gettimeofday(&last,0);
00209         blinkness = blink.findBlinks(pixels, faces); // mpisearch.search(pixels, faces, 1);
00210         gettimeofday(&tv_now,0);
00211         if(fc == 0){
00212           cout << "blinkness: " << blinkness << endl;
00213           printf("\tThe first search took %g seconds. \n", difftv(tv_now, last));
00214           printf("Initially found %d faces in %s.\n", faces.size(), arguments.args[arg_count]);
00215         }
00216         faces.simplify( 0.2 ); //0.24);
00217         if(fc == 0){
00218           printf("Now found %d.\n", faces.size());
00219           gettimeofday(&tv_first,0);
00220         }
00221       }
00222       gettimeofday(&final,0);
00223       cout << "blinkness: " << blinkness << endl;
00224       printf("\tTheoretical frame rate for one-face tracking & blink detection: %g fps. \n", (nframes-1) / difftv(final, tv_first));
00225       
00226 
00227       if(faces.size() != 0) {
00228         image.strokeColor("white");
00229         image.strokeWidth(1);
00230         image.fillColor("none" );
00231 
00232         while(!faces.empty( ))
00233         {
00234           Square face = faces.front();  
00235           faces.pop_front();
00236 
00237           image.draw( DrawableRectangle(face.x, face.y, 
00238                 face.x + face.size, face.y + face.size));
00239        }        
00240         image.display();
00241       }
00242     }
00243     catch ( ErrorFileOpen &error ) {
00244       cerr << "Error opening file: " 
00245            <<  arguments.args[arg_count]
00246            << ". ImageMagick said: " 
00247            << error.what() 
00248            << endl;
00249     }
00250   } 
00251   return 0;
00252 }

Here is the call graph for this function:

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

Definition at line 84 of file Libraries/blinkDetector/src/main.cc.

References arguments::args, arguments::cfile, arguments::emofile, arguments::emoFlag, arguments::matfile, arguments::matlab, and state.

00084                                                                        {
00085   // Get input argument from argp_parse, which is our
00086   // arguments pointer.
00087   struct arguments *arguments = static_cast<struct arguments *>(state->input);
00088   
00089   switch(key)
00090     {
00091     case 'm':
00092       arguments->matlab = 1;
00093       if(arg) strcpy(arguments->matfile, arg);
00094       break;
00095     case 'c':
00096       strcpy(arguments->cfile, arg);
00097       break;
00098     case 'e':
00099       arguments->emoFlag = 1;
00100       break;
00101     case 'o':
00102       arguments->emoFlag = 2;
00103       strcpy(arguments->emofile,"nonconvEmo.xml");
00104       break;
00105     case 'f':
00106       strcpy(arguments->emofile, arg);
00107       break;
00108     case ARGP_KEY_ARG:
00109       if(state->arg_num >= 10)   // too many arguments
00110         argp_usage (state);
00111       arguments->args[state->arg_num] = arg;
00112       break;
00113     case ARGP_KEY_NO_ARGS:
00114       argp_usage(state);
00115       break;
00116     case ARGP_KEY_END:
00117       if (state->arg_num <= 0) // not enough arguments
00118         argp_usage(state);
00119       break;
00120 
00121     default:
00122       return ARGP_ERR_UNKNOWN;
00123     }
00124   return 0;
00125 }


Variable Documentation

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

Definition at line 128 of file Libraries/blinkDetector/src/main.cc.

Referenced by main().

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

Definition at line 61 of file Libraries/blinkDetector/src/main.cc.

const char* argp_program_version = "2.0"
 

Definition at line 60 of file Libraries/blinkDetector/src/main.cc.

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

Definition at line 127 of file Libraries/blinkDetector/src/main.cc.

char doc[] [static]
 

Initial value:

 "Feature based Face detection, from the Machine Perception Lab at UCSD."
"Previous version was called viola++, after Paul Viola, who described the original algorithm."
"  To just 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 62 of file Libraries/blinkDetector/src/main.cc.

struct argp_option options[] [static]
 

Initial value:

 {

  {"cfile", 'x', "XMLFILE", 0, "Use classifier specified in the xml file XMLFILE"},
  {"emotion", 'e', 0, 0, "Use emotion recognition using convolutions on found faces"},
  {"nonconvemotion", 'o', 0, 0, "Use emotion recognition using other filters on found faces"},
  {"emofile", 'f', "EMOFILE", 0, "Use emotion recognizer weights specified in the xml file EMOFILE"},
  {0}
}

Definition at line 68 of file Libraries/blinkDetector/src/main.cc.


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